可在Android中,以findView通过串号? [英] Is possible in Android to findView by String id?

查看:98
本文介绍了可在Android中,以findView通过串号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是可能的Adroid到findView通过串号?我在表中添加一些行编程和下一次迭代需要删除其中的一些,我有表ID(tblRow_1,tblRow_3..})。我可以检索由IDS从列表?

Is possible in adroid to findView by String id ? I add some rows in table programmatically and in next iteration need to remove some of them and I have List id ( "tblRow_1", "tblRow_3" ..}). Can I retrieve by ids from list ?

推荐答案

使用<一个href="http://developer.android.com/reference/android/content/res/Resources.html#getIdentifier%28java.lang.String,%20java.lang.String,%20java.lang.String%29"><$c$c>getResources().getIdentifier()检索实际整数资源ID。

Use getResources().getIdentifier() to retrieve the actual integer resource ID.

例如

int resID = getResources().getIdentifier(stringVar, "id", "com.sample.project");
view = findViewById(resID);

这篇关于可在Android中,以findView通过串号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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