Good morning, I have the following error:
When trying to validate my fields by clicking the register button, it does not take any action .. I am new to android and would like help.
Thank you.
package com.example.eduardo.jfdigital;
import android.support.annotation.Nullable;
import android.support.annotation.StringDef;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Patterns;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.example.eduardo.jfdigital.R;
import java.util.regex.Pattern;
import static com.example.eduardo.jfdigital.R.id.confSenha;
import static com.example.eduardo.jfdigital.R.id.email;
import static com.example.eduardo.jfdigital.R.id.frame_layout;
import static com.example.eduardo.jfdigital.R.id.login;
import static com.example.eduardo.jfdigital.R.id.nome;
import static com.example.eduardo.jfdigital.R.id.senha;
public class efetuarcadastro extends android.support.v4.app.Fragment {
View myView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
myView = inflater.inflate( R.layout.efetuarcadastro, container,false);
myView.findViewById( R.id.cad );
myView.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
validaCampos();
}
/* nome.setOnFocusChangeListener( new View.OnFocusChangeListener() {
@Override
public String toString() {
return "$classname{}";
}
@Override
public void onFocusChange(View view, boolean b) {
if ((nome.getText().length() < 1))
{
nome.setError( "Campo obrigatório" );
}
else
if ((login.getText().length() < 1))
{
login.setError( "Campo obrigatório" );
}
else
if ((email.getText().length() < 1))
{
email.setError( "Campo obrigatório" );
}
}
} ); */
EditText nome = myView.findViewById( R.id.nome );
EditText login = myView.findViewById( R.id.login );
EditText email = myView.findViewById( R.id.email );
EditText senha = myView.findViewById( R.id.senha );
EditText confSenha = myView.findViewById( R.id.confSenha );
/* nome = (EditText) findViewById( R.id.nome);
login = (EditText) findViewById(R.id.login);
email = (EditText) findViewById( R.id.email);
senha = (EditText) findViewById( R.id.senha);
confSenha = (EditText) findViewById( confSenha); */
private void validaCampos() {
boolean res = false;
String name = nome.getText().toString();
String user = login.getText().toString();
String emails = email.getText().toString();
String password = senha.getText().toString();
String confpass = confSenha.getText().toString();
if (res = verificaCampovazio( name )) {
nome.requestFocus();
} else
if (res = verificaCampovazio( user )) {
login.requestFocus();
AlertDialog.Builder Mcampovazio = new AlertDialog.Builder(efetuarcadastro.this.getActivity());
} else
if (res = !emailValidar( emails )) {
email.requestFocus();
} else
if (res = verificaCampovazio( password )) {
senha.requestFocus();
} else
if (res = verificaCampovazio( confpass )) {
confSenha.requestFocus();
if (res) {
AlertDialog.Builder Mcampovazio = new AlertDialog.Builder(efetuarcadastro.this.getActivity());
Mcampovazio.setTitle( "Aviso: " );
Mcampovazio.setMessage( "Há campos inválidos ou sem preenchimento" );
Mcampovazio.setNeutralButton( "OK",null );
Mcampovazio.show(); }
}
}
private boolean verificaCampovazio(String valor) {
Boolean resultado = (TextUtils.isEmpty( valor ) || valor.trim().isEmpty());
return resultado;
}
private boolean emailValidar(String email) {
Boolean resultado = (!verificaCampovazio( email ) && Patterns.EMAIL_ADDRESS.matcher( email ).matches());
return resultado;
}
} );
return myView;
}
}