Currently I have two edit-text,suppose I want to make validation for empty edittext check.What is better way for runtime validation.
My code is;
final EditText ev1 = (EditText) findViewById(R.id.editText1);
final EditText ev2 = (EditText) findViewById(R.id.editText2);
ev1.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View rv, boolean hasFocus) {
if(!hasFocus && ev1.getText().length()==0)
{
ev1.requestFocus();
ev2.clearFocus();
}
}
});
In this onclick of second editText it clears the focus of second EditText when First Edittext is empty,but keyboard entries always done in Second Text,and we can never get focus in First Text.
Please don't suggest different different focus listener for different EditText as this editText may be added dynamically too.
More CLEARLY:Just simple thing to validate ev1 before losing focus,not allow other views to get focus until any character is entered in it.
I have taken on xml having two textboxes and tried this way to solve your issue.
check the below code and tell me is it ok for you?
Try this :
EDIT :
Declare this method :
Thanks.