Android Java采用所有editText';马上
我的xml文件中有大约200个editText 我想在java文件中一次获取所有输入值 有没有办法不用找到所有200个ID就可以做到这一点。试试这个:Android Java采用所有editText';马上,java,android,Java,Android,我的xml文件中有大约200个editText 我想在java文件中一次获取所有输入值 有没有办法不用找到所有200个ID就可以做到这一点。试试这个: private LinearLayout ll; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.m
private LinearLayout ll;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
ll=(LinearLayout)findViewById(R.id.ll_view);
final int childcount = ll.getChildCount();
for (int i = 0; i < childcount; i++) {
View v = ll.getChildAt(i);
if (v instanceof EditText) {
Log.d("EditText Value", ((EditText) v).getText().toString());
}
}
}
专线布局ll;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(右布局、主布局);
ll=(线性布局)findViewById(R.id.ll_视图);
final int childcount=ll.getChildCount();
for(int i=0;i
在linearlayout中创建200个编辑文本
LinearLayout mRlayout = (LinearLayout) findViewById(R.id.llMainLayout);
LinearLayout.LayoutParams mRparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)
for (int i = 0; i < 200; i++) {
EditText myEditText = new EditText(context);
myEditText.setLayoutParams(mRparams);
mRlayout.addView(myEditText);
}
LinearLayout mRlayout=(LinearLayout)findViewById(R.id.llmainllayout);
LinearLayout.LayoutParams mRparams=新的LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_父项,LinearLayout.LayoutParams.WRAP_内容)
对于(int i=0;i<200;i++){
EditText myEditText=新的EditText(上下文);
myEditText.setLayoutParams(mRparams);
mRlayout.addView(myEditText);
}
检索arraylist中的值的步骤
ArrayList<String> alEditTextInputs = new ArrayList<>();
for(int j=0;j<mRlayout.getChildCount();j++){
alEditTextInputs.add(((EditText)mRlayout.getChildAt(j)).getText().toString());
}
ArrayList alEditTextInputs=new ArrayList();
对于(int j=0;j,您需要在父视图中进行递归调用,以在视图中查找Edittext
的实例
ViewGroup viewGroup = //Your parent layout it render your child view.
int count = viewGroup .getChildCount();
for(int i =0;i<count;i++)
{
View v = viewGroup .getChildAt(i);
if(v instanceof Edittext)
{
// you got the edittext
EditText s = (EditText) v;
Log.i("Item selected",s.getText().toString());
}
}
ViewGroup ViewGroup=//您的父布局,它将呈现您的子视图。
int count=viewGroup.getChildCount();
对于(int i=0;i请点击此链接
请提供任何示例代码?在我看来,将用户键入的内容转换为200个编辑文本不是很好的用户体验。我肯定会很恼火。我同意@Sweeper,这绝对不是一个好的用户体验。也许你可以通过使用分页制作少量编辑文本来改进它。