Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. @Nullable
  2. @Override
  3. public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  4. myView = inflater.inflate( R.layout.efetuarcadastro, container,false);
  5.  
  6. myView.findViewById( R.id.cad );
  7. myView.setOnClickListener( new View.OnClickListener() {
  8. @Override
  9. public void onClick(View v) {
  10.  
  11. validaCampos();
  12. }
  13.  
  14.  
  15. /* nome.setOnFocusChangeListener( new View.OnFocusChangeListener() {
  16. @Override
  17. public String toString() {
  18. return "$classname{}";
  19. }
  20.  
  21. @Override
  22. public void onFocusChange(View view, boolean b) {
  23.  
  24.  
  25. if ((nome.getText().length() < 1))
  26.  
  27. {
  28. nome.setError( "Campo obrigatório" );
  29. }
  30.  
  31. else
  32. if ((login.getText().length() < 1))
  33.  
  34. {
  35. login.setError( "Campo obrigatório" );
  36. }
  37.  
  38. else
  39. if ((email.getText().length() < 1))
  40.  
  41. {
  42. email.setError( "Campo obrigatório" );
  43. }
  44.  
  45.  
  46. }
  47.  
  48. } ); */
  49.  
  50. EditText nome = myView.findViewById( R.id.nome );
  51. EditText login = myView.findViewById( R.id.login );
  52. EditText email = myView.findViewById( R.id.email );
  53. EditText senha = myView.findViewById( R.id.senha );
  54. EditText confSenha = myView.findViewById( R.id.confSenha );
  55.  
  56. /* nome = (EditText) findViewById( R.id.nome);
  57. login = (EditText) findViewById(R.id.login);
  58. email = (EditText) findViewById( R.id.email);
  59. senha = (EditText) findViewById( R.id.senha);
  60. confSenha = (EditText) findViewById( confSenha); */
  61.  
  62.  
  63. private void validaCampos() {
  64.  
  65. boolean res = false;
  66. String name = nome.getText().toString();
  67. String user = login.getText().toString();
  68. String emails = email.getText().toString();
  69. String password = senha.getText().toString();
  70. String confpass = confSenha.getText().toString();
  71.  
  72. if (res = verificaCampovazio( name )) {
  73. nome.requestFocus();
  74. } else
  75. if (res = verificaCampovazio( user )) {
  76. login.requestFocus();
  77. AlertDialog.Builder Mcampovazio = new AlertDialog.Builder(efetuarcadastro.this.getActivity());
  78. } else
  79. if (res = !emailValidar( emails )) {
  80. email.requestFocus();
  81. } else
  82. if (res = verificaCampovazio( password )) {
  83. senha.requestFocus();
  84. } else
  85. if (res = verificaCampovazio( confpass )) {
  86. confSenha.requestFocus();
  87.  
  88. if (res) {
  89. AlertDialog.Builder Mcampovazio = new AlertDialog.Builder(efetuarcadastro.this.getActivity());
  90. Mcampovazio.setTitle( "Aviso: " );
  91. Mcampovazio.setMessage( "Há campos inválidos ou sem preenchimento" );
  92. Mcampovazio.setNeutralButton( "OK",null );
  93. Mcampovazio.show(); }
  94.  
  95. }
  96. }
  97.  
  98. private boolean verificaCampovazio(String valor) {
  99.  
  100. Boolean resultado = (TextUtils.isEmpty( valor ) || valor.trim().isEmpty());
  101.  
  102. return resultado;
  103. }
  104.  
  105. private boolean emailValidar(String email) {
  106.  
  107. Boolean resultado = (!verificaCampovazio( email ) && Patterns.EMAIL_ADDRESS.matcher( email ).matches());
  108.  
  109. return resultado;
  110.  
  111.  
  112. }
  113.  
  114. } );
  115.  
  116. return myView;
  117. }
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement