2010-05-04 87 views
0

假设我在应用程序中有多个EditText。当我点击一个按钮时,我想测试EditTexts是空的还是EditTexts的内容。我也想要内容不为空的EditText的id。我会怎么做?有人可以编写Button单击处理程序的代码。我的EditText的六个ID是FirstString,SecondString,ThirdString,... Button的id是按钮。测试多个EditText是否为空

回答

1

只需在设置视图时为该类创建一个数组,并在按钮按下时检查每个数组。如果没有看到你已经有的东西,就不能真正编写代码。

0

你总是可以通过父视图的孩子循环:

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... 
}