Test if Multiple EditTexts are empty
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开发者_C百科 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.
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.
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...
}
精彩评论