基本上,我有一个 LinearLayout,它包含随机数量的水平 LinearLayout,并且在每个水平 LinearLayout 中都有一个 TextView 和一个 EditText。我希望能够获得主 LinearLayout 的每个 EditText 子项的值。
对不起,如果它令人困惑,我不擅长解释事情!
我可以为每个 EditText 设置相同的 ID 然后使用 findViewById,还是只返回 EditText 的第一个实例?
谢谢, 亚历克斯。
最佳答案
LinearLayout ll = //Your Layout this can be any Linear or Relative layout
//in which you added your spinners at runtime ;
int count = ll.getChildCount();
for(int i =0;i<count;i++)
{
View v = ll.getChildAt(i);
if(v instanceof Spinner)
{
// you got the spinner
EditText s = (EditText) v;
Log.i("Item selected",s.getText().toString());
}
}
关于java - 安卓开发 : How To Get All EditText Children of a ViewGroup?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5638670/