5

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?

Axifive
  • 1,159
  • 2
  • 19
  • 31
Damir
  • 54,277
  • 94
  • 246
  • 365

2 Answers2

17

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

example

int resID = getResources().getIdentifier(stringVar, "id", "com.sample.project");
view = findViewById(resID);
jondavidjohn
  • 61,812
  • 21
  • 118
  • 158
1

You can use Resources.getIdentifier() for this.

inazaruk
  • 74,247
  • 24
  • 188
  • 156