lacas
lacas

Reputation: 14066

Android findViewbyId with a variant string

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

Upvotes: 10

Views: 7578

Answers (1)

Felix
Felix

Reputation: 89566

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);
}

Upvotes: 25

Related Questions