可在Android中,以findView通过串号?可在、Android、findView

2023-09-06 10:44:30 作者:不囍人潮

是可能的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 ?

推荐答案

使用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);