Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android findViewbyId with a variant string

Tags:

android

TextView textView1= (TextView) dialog.findViewById(R.id.textView1);

I d like to create something like this:

for (int i=0; i<100; i++) {
   TextView textView= (TextView) dialog.findViewById(R.id.textView+i);
}

how can i do that?

Leslie

like image 803
lacas Avatar asked Jul 13 '11 13:07

lacas


1 Answers

See getIdentifier. Basically, you want something like:

for (int i=0; i<100; i++) {
   int resId = getResources().getIdentifier("textView" + i, "id", getPackageName());
   TextView textView = (TextView) dialog.findViewById(resId);
}
like image 69
Felix Avatar answered Sep 28 '22 01:09

Felix