如何从动态创建的EditText字段中获取值? [英] How to get values from dynamically created EditText fields?
问题描述
我对以下情况有点困惑:
I am little confused with following scenario:
我有一个添加按钮,用它可以添加许多EditText
字段,当我点击保存按钮时,我应该从EditText
s中获取值.
I have an add button which I use it to add a number of EditText
fields, when I tap on the save button I should get the values from the EditText
s.
如何从所有EditText字段中获取这些值?
How can I get these values from all of the EditText fields?
推荐答案
您可以执行以下操作:
将您以编程方式创建的所有EditText字段存储在列表中.因此,每当您拥有viewGroup.add(myEditText);
时,您也会拥有myList.add(myEditText);
Store all the EditText fields you create programmatically inside a List. So whenever you have viewGroup.add(myEditText);
you would also have myList.add(myEditText);
然后,当您按保存"时,在列表上循环并使用getText()
从EditText字段中获取数据.
Then when you press 'save' just loop on your list and use getText()
to get the data from your EditText fields.
我确定还有其他方法可以完成此操作;)
I'm sure there are also other ways to accomplish this ;)
这篇关于如何从动态创建的EditText字段中获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!