Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is possible in Android to findView by String id?

Tags:

android

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?

like image 676
Damir Avatar asked Aug 10 '11 18:08

Damir


2 Answers

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

example

int resID = getResources().getIdentifier(stringVar, "id", "com.sample.project");
view = findViewById(resID);
like image 73
jondavidjohn Avatar answered Oct 06 '22 02:10

jondavidjohn


You can use Resources.getIdentifier() for this.

like image 44
inazaruk Avatar answered Oct 06 '22 00:10

inazaruk