title: Setting Android images from string value
body: <p>Currently I'm drawing a PNG image in my Android application like so: </p>
  
  <pre><code>ImageView image = new ImageView(context);
  image.setImageDrawable(context.getResources().getDrawable(R.drawable.testimage))
  </code></pre>
  
  <p>If I have a list of image names in a database, is there a way to set the drawable above using the image name? I already have the code to go through the database, I'm just looking to draw the image based on the value taken from here.</p>
  
  <p>For example, a record for the DB:</p>
  
  <pre><code>ID:    Name:    ImageName:
  -      Test     testimage
  </code></pre>
  
  <p>So when I'm reading this record, I have a string with the value of "testimage" and I'd then want to set the image drawable to <code>R.drawable.testimage</code>.</p>
  
  <p>One way I was thinking of doing it would be something like this:</p>
  
  <pre><code>int image = R.drawable.blank; // blank image
  
  // testimage.png is the image name from the database
  if(imageName.toString().equals("testimage.png"))
      image = R.drawable.testimage;
  else if(imageName.toString().equals("another.png"))
      image = R.drawable.another;
  else if(imageName.toString().equals("etc.png"))
      image = R.drawable.etc;
  </code></pre>
  
  <p>However this isn't very efficient!</p>
  
  <p>Thanks</p>