title: Programatically setting a random image to an ImageButton
body: <p>I'm trying to have the picture used by my <code>ImageButton</code> to be selected randomly.</p>
  
  <p>I think this code should work but there seems to be a problem when passing the resource as a <code>String</code>.</p>
  
  <pre><code>    ImageButton getClickTime = (ImageButton) findViewById(R.id.clicker);
  
      Random generator = new Random();
      int generatedRandom = generator.nextInt(10) + 1;
      String randomImage = "R.drawable.bg" + (String.valueOf(generatedRandom)) ;
      Drawable replaceImage = getResources().getDrawable((int) randomImage);
  
      getClickTime.setImageDrawable((Drawable) replaceImage);
  </code></pre>
  
  <p>I seem to be getting in a bit of a mess with casts of <code>int</code>s, <code>String</code>s, <code>drawable</code>s and <code>CharSequence</code>s. </p>
  
  <p>If I manually type in a randomly selected image resource, it works. But if I pass the <code>String</code> to a text-box I can see that it's written exactly the same as when I type it in manually.</p>
  
  <p>Can anyone see what I'm doing wrong here?</p>
  
  <p>Thanks in advance</p>