Is possible in Android to findView by String id?

2020-03-03 08:58发布

Is possible in Android 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 the list?

标签: android
2条回答
▲ chillily
2楼-- · 2020-03-03 09:11

You can use Resources.getIdentifier() for this.

查看更多
放我归山
3楼-- · 2020-03-03 09:13

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

example

int resID = getResources().getIdentifier(stringVar, "id", "com.sample.project");
view = findViewById(resID);
查看更多
登录 后发表回答