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,117
  • 2
  • 20
  • 30
Damir
  • 51,611
  • 92
  • 240
  • 358

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
  • 60,871
  • 21
  • 115
  • 157
1

You can use Resources.getIdentifier() for this.

inazaruk
  • 73,337
  • 23
  • 185
  • 156