I want to use some views ID’s, and I want a loop to iterate through all of them.
Here’s what I mean:
for (int i = 0;i<10;i++) {
TextView tv = (TextView) findViewById(R.id.txt+i);
}
Of course it is wrong, but lets say I have in the layout 10 TextViews:
txt0
txt1
txt2
.
.
.
txt9
I want the loop to perform something like this:
TextView tv = (TextView) findViewById(R.id.txt0);
TextView tv = (TextView) findViewById(R.id.txt1);
.
.
.
TextView tv = (TextView) findViewById(R.id.txt+9);
Is it possible??
Thanks!
You can find the ID by name like this:
However, this just assigns a textview 10 times. What are you doing after this? I can’t see how this is useful but perhaps you can build on it.