Showing posts with label read all. Show all posts
Showing posts with label read all. Show all posts

Tuesday, 30 April 2013

Read All empty Edit text box in an Activty




public static EditText traverseEditTexts(ViewGroup v) {
  EditText invalid = null;
  for (int i = 0; i < v.getChildCount(); i++) {
   Object child = v.getChildAt(i);
   if (child instanceof EditText) {
    EditText e = (EditText) child;
    if (e.getText().length() == 0) // Whatever logic here to
        // determine if valid.
    {
     return e; // Stops at first invalid one. But you could add
        // this to a list.
    }
   } else if (child instanceof ViewGroup) {
    invalid = traverseEditTexts((ViewGroup) child); // Recursive
                // call.
    if (invalid != null) {
     break;
    }
   }
  }
  return invalid;
 }

Use the Above function to search a edit text in the Activty 
 
private boolean validateFields() {
  ViewGroup MainLayout = (ViewGroup) findViewById(R.id.LoginParentLayout);
  EditText emptyText = FormValidation.traverseEditTexts(MainLayout);
  if (emptyText != null) {
   String field = emptyText.getHint().toString();
   showToast(field + "  field cannot be empty.");
   emptyText.requestFocus(); // Scrolls view to this field.
  }
  return emptyText == null;
 }


 

Disqus for Android