Guest User

Fragment_step_1

a guest
Oct 6th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.35 KB | None | 0 0
  1. public class Fragment_step_1 extends Fragment {
  2. public pingan_hkidValidate class_checkHKID;
  3. RelativeLayout personal;
  4. TextInputLayout floatingName, floatingHKID, floatingEmail, floatingTel;
  5. EditText name, getEmail, HKIDNumber, phone;
  6. String check_digit, check_IDchar, check_IDNum;
  7.  
  8. @Override
  9. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  10. personal = (RelativeLayout)inflater.inflate(R.layout.reg_step_personal, container, false);
  11. name = (EditText)personal.findViewById(R.id.txtFullName);
  12. getEmail = (EditText)personal.findViewById(R.id.txtEmail);
  13. HKIDNumber = (EditText)personal.findViewById(R.id.txtHKIDNumber);
  14. phone = (EditText)personal.findViewById(R.id.txtPhoneNumber);
  15. class_checkHKID = new pingan_hkidValidate();
  16. floatingName = (TextInputLayout)personal.findViewById(R.id.til_et_full_name);
  17. floatingHKID = (TextInputLayout)personal.findViewById(R.id.til_et_HKID);
  18. floatingEmail = (TextInputLayout)personal.findViewById(R.id.til_et_email);
  19. floatingTel = (TextInputLayout)personal.findViewById(R.id.til_et_tel);
  20.  
  21. name.addTextChangedListener(new TextWatcher() {
  22. @Override
  23. public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
  24.  
  25. @Override
  26. public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
  27.  
  28. @Override
  29. public void afterTextChanged(Editable editable) {
  30. if("".trim().equals(name.getText().toString())){
  31. floatingName.setError("Your Name is required.");
  32. } else {
  33. floatingName.setErrorEnabled(false);
  34. floatingName.setError(null);
  35. }
  36. }
  37. });
  38.  
  39.  
  40. getEmail.addTextChangedListener(new TextWatcher(){
  41. @Override
  42. public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
  43.  
  44. @Override
  45. public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
  46.  
  47. @Override
  48. public void afterTextChanged(Editable editable) {
  49. if (!getEmail.getText().toString().trim().matches("^\\S+@\\S+\\.\\S+$") || "".trim().equals(getEmail.getText().toString())) {
  50. floatingEmail.setError("The email format is invalid.");
  51. } else {
  52. floatingEmail.setErrorEnabled(false);
  53. floatingEmail.setError(null);
  54. }
  55. }
  56. });
  57.  
  58. HKIDNumber.addTextChangedListener(new TextWatcher() {
  59. @Override
  60. public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
  61.  
  62. @Override
  63. public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
  64.  
  65. @Override
  66. public void afterTextChanged(Editable editable) {
  67. HKIDNumber.setOnFocusChangeListener(new View.OnFocusChangeListener(){
  68. @Override
  69. public void onFocusChange(View View, boolean isFocus) {
  70. if (!isFocus) {
  71. //Log.e("ID", strIDNum);
  72. if ("".trim().equals(HKIDNumber.getText().toString().trim())) {
  73. floatingHKID.setErrorEnabled(true);
  74. floatingHKID.setError("HKID Number is required.");
  75. } else {
  76. check_IDchar = HKIDNumber.getText().toString().trim().substring(0, 1);
  77. check_IDNum = HKIDNumber.getText().toString().trim().substring(1, HKIDNumber.getText().toString().trim().length() - 1);
  78. check_digit = HKIDNumber.getText().toString().trim().substring(HKIDNumber.getText().toString().trim().length() - 1);
  79. if (!class_checkHKID.validate(check_IDchar, check_IDNum, check_digit)) {
  80. floatingHKID.setErrorEnabled(true);
  81. floatingHKID.setError("Your HKID Number is invalid.");
  82. } else {
  83. floatingHKID.setErrorEnabled(false);
  84. floatingHKID.setError(null);
  85. }
  86. }
  87. }
  88. }
  89. });
  90. }
  91. });
  92.  
  93. phone.addTextChangedListener(new TextWatcher() {
  94. @Override
  95. public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
  96.  
  97. @Override
  98. public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
  99.  
  100. @Override
  101. public void afterTextChanged(Editable editable) {
  102. if("".trim().equals(phone.getText().toString()) || phone.getText().toString().trim().length() < 8){
  103. floatingTel.setError("Phone Number is required / must be 8 in length.");
  104. } else {
  105. floatingTel.setErrorEnabled(false);
  106. floatingTel.setError(null);
  107. }
  108. }
  109. });
  110. return personal;
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment