Damir
Damir

Reputation: 56199

Is possible in Android to findView by String id?

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?

Upvotes: 5

Views: 4783

Answers (2)

jondavidjohn
jondavidjohn

Reputation: 62392

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

example

int resID = getResources().getIdentifier(stringVar, "id", "com.sample.project");
view = findViewById(resID);

Upvotes: 17

inazaruk
inazaruk

Reputation: 74780

You can use Resources.getIdentifier() for this.

Upvotes: 1

Related Questions