I'm trying to enable a button but first I want to check that the editText have content and then enable the button. Here is my code. What should be the best solution?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
rootView =inflater.inflate(R.layout.fragment_sign_up_part_two, container, false);
app();
return rootView;
}
public void app(){
etCorreo = (EditText)rootView.findViewById(R.id.tvCorreoUsuario);
etPassword = (EditText)rootView.findViewById(R.id.tvPassword);
btnRegistrarse = (Button)rootView.findViewById(R.id.btnRegistro);
events();
}
public void events(){
if(validate()){
btnRegistrarse.setEnabled(true);
btnRegistrarse.setClickable(true);
}
}
public Boolean validate(){
correo = etCorreo.getText().toString().trim();
pass = etPassword.getText().toString().trim();
if(correo.isEmpty()) return false;
if(pass.isEmpty()) return false;
return true;
}
And this is my xml
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btn_registrarse"
android:id="@+id/btnRegistro"
android:enabled="false"
android:layout_gravity="center_horizontal"
android:background="@color/background_color"
android:layout_margin="10dp"
/>