假设我在一个应用程序中有多个 EditText。当我点击一个按钮时,我想测试哪些 EditTexts 是空的,哪些 EditTexts 有内容。我还想要内容不为空的 EditText 的 id。我该怎么做?有人可以为按钮单击处理程序编写代码。我的六个 EditText 的 id 是 FirstString、SecondString、ThirdString,... Button 的 id 是 button。
1337 次
2 回答
2
只需在设置视图时为保存它们的类创建一个数组,然后在按下按钮时检查每一个。如果没有看到你已经拥有的东西,就无法真正编写代码。
于 2010-05-04T20:28:11.080 回答
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...
}
于 2010-05-05T20:07:05.150 回答