在我的Activity中,动态插入包含EditText的布局。布局可以在一个和N EditText之间。如何获取所有EditText的文本?
LinearLayout item = (LinearLayout) findViewById(R.id.rl);
final View child = getLayoutInflater().inflate(R.layout.inflate_ta, null);
item.addView(child);
MaterialEditText ed = (MaterialEditText) child.findViewById(R.id.ed12);
ed.setFloatingLabelText(edNomeCampo.getText().toString());
答案 0 :(得分:1)
最好的方法是在您动态添加的任何父视图中浏览每个视图。
所以...
<LinearLayout
android:id="@+id/wrapper"..>
<EditText ... />
<EditText... />
...
...
<!--Nth EditText-->
<EditText... />
</LinearLayout>
然后,一旦您想要获取每个动态添加的EditText
中的值,您将遍历该包装中的所有视图LinearLayout
LinearLayout yourLinearLayoutView = (LinearLayout)getView().findViewById(R.id.wrapper);
for(int i=0; i<yourLinearLayoutView.getChildCount(); i++) {
View editText= yourLinearLayoutView.getChildAt(i);
if(editText instanceof EditText){
String str = ((EditText)editText).getText();
//from here you can store str in whatever structure you wish (AWrrayList, etc.)
}
}