title: Android: Using loops to fill an array with image ID's
body: <p>Similar question to <a href="https://stackoverflow.com/questions/3026639/android-set-a-random-image-using-setimageresource">Android: Set a random image using setImageResource</a>, but I think I'm looking for a different answer.</p>
  
  <p>As mentioned in the linked post, this:</p>
  
  <pre><code>int p = R.drawable.photo;
  image.setImageResource(p);
  </code></pre>
  
  <p>displays photo1, but something like this:</p>
  
  <pre><code>String a = "R.drawable.";
  String b = "photo";
  String c = a+b;
  int p = Integer.parseInt(c);
  image.setImageResource(p);
  </code></pre>
  
  <p>will not. I have a lot of images, and an array contining all of the image names, so I want to fill an array something like:</p>
  
  <pre><code>int imageArray[] = new int[number_of_images];
  for (int i = 0; i &lt; numImages; i++)
  imageArray[i] = ("R.drawable." + image_names[i]);
  </code></pre>
  
  <p>but I get a runtime error. Is there any way to make this loop work? Or better ways to cue up image ID's into an array?</p>
  
  <p>Thanks!</p>