-1

I'm making an layout with 400 imageView. The question is how I can set R.id.imageView>>i<<

for(int i = 1; i < 401; i++){
    ImageView imageView = (ImageView)findViewById(R.id.imageView-i-);
}
Halvor Holsten Strand
  • 19,829
  • 17
  • 83
  • 99
ledther0n
  • 1
  • 1
  • possible duplicate of [How can i access an Android drawable by a variable](http://stackoverflow.com/questions/3218520/how-can-i-access-an-android-drawable-by-a-variable) – Lachlan Goodhew-Cook Mar 10 '15 at 22:16
  • 1
    Also possible duplicate of http://stackoverflow.com/questions/4865244/android-using-findviewbyid-with-a-string-in-a-loop ? – Jonathan Mar 10 '15 at 22:18

1 Answers1

0
for (int i = 1; i <= 400; i++) {
    String s = "imageview" + i;
    int id = getResources.getIdentifier(s, "id", getPackageName ());
    ImageView imageview = (ImageView)findViewById (id);
}

This should work

Lachlan Goodhew-Cook
  • 1,101
  • 17
  • 31
Joeri
  • 85
  • 7