Wednesday, February 1, 2012

How to validate all EditText in activty for not being blank?


Call the below method....

ViewGroup root = (ViewGroup) findViewById(R.id.main_root);


private boolean validate() {
final int childrenCount = root.getChildCount();
for (int i = 0; i < childrenCount; i++) {
View child = root.getChildAt(i);
if (child instanceof EditText) {
if (TextUtils.isEmpty(((EditText) child).getText().toString()))
return false;
}
}
return true;
}

No comments:

Post a Comment