views:

150

answers:

2

Say I have multiple EditTexts in an application. When I click a Button, I want to test what EditTexts are empty and what EditTexts have content. I also want the id of the EditText whose content is NOT empty. How would I do that? Could someone write the code for the Button click handler. My six EditText's ids are FirstString, SecondString, ThirdString, ... The Button's id is button.

+1  A: 

Just create an array for the class holding them when you set up the view, and check each one on the button press. Can't really write the code without seeing what you had already.

AaronM
A: 

You could always loop through the children of the parent view:

View parent = findViewById(R.id.parentlayout_id);
for(int i = 0; i < parent.getChildCount(); i++){
   View v = parent.getChildAt(i);
   if(v instanceof EditText)
      //cast it and check the text here...
}
Ricardo Villamil