测试多个EditTexts是否为空

时间:2010-05-04 20:23:40

标签: java android events android-edittext

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

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

您始终可以遍历父视图的子项:

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...
}
相关问题