如何从动态创建的 EditText 字段中获取值? [英] How to get values from dynamically created EditText fields?

查看:25
本文介绍了如何从动态创建的 EditText 字段中获取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对以下场景有点困惑:

I am little confused with following scenario:

我有一个添加按钮,我用它来添加许多 EditText 字段,当我点击保存按钮时,我应该从 EditText 中获取值.

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 EditTexts.

如何从所有 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆