如何在Android中将动态字符串设置为Edittext字段的ID [英] How can I set a dynamic string as an Id of an Edittext Field in android
问题描述
我有多个字符串,它们是动态变化的,我想将这些字符串设置为表单中EditText字段的ID.我该怎么办,您能帮我吗?
I am having Multiple Strings, that are coming dynamically, I want to set these strings as Id of the EditText Fields in my Form. How can I do that, can you please help me?
例如:如果我的ID为"title",则希望将此标题设置为EditText字段的ID,以便当我要访问该字段的值时,可以像findviewById(title)一样对其进行访问.
For Ex: If I am having id "title", I want to set this title as id of the EditText Field, so that when I want to access the value of this field, I can access it like findviewById(title).
请在这里帮助我...
Please help me here...
非常感谢您.
推荐答案
否,您不能将id
设置为char
,String
或除int
之外的任何其他设置. ..因为id
由仅包含int
的R.java
文件维护.
No, You can't set id
with char
, String
or anything else except int
...because, id
is maintained by R.java
file which contains only int
.
您可以使用setTag()
代替setId()
.
按以下方式使用setTag()
...
Use setTag()
as below...
edText.setTag("title");
您以后可以使用 getTag() edText.getTag()进行检查.
You can later check it using getTag() edText.getTag().
您可以使用 findViewWithTag 来查找带有特定标签的视图.
You can use findViewWithTag in order to find the view with a specific tag.
这篇关于如何在Android中将动态字符串设置为Edittext字段的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!