Can someone please help with this. I am generating a random number and based on this random number I want to pick a png file from my res/drawable-mdpi folder to display. This is the code I’m using:
public void DisplayRandomPicture(int randomNumber)
{
String drawableName = "c"+ randomNumber;
ImageView image= (ImageView)findViewById(R.id.imageView1);
image.setImageDrawable(getResources().getDrawable(getResources().getIdentifier(drawableName, "res/drawable-mdpi", getPackageName())));
}
All the files in the res/drawable-mdpi folder start with “c”. There is something wrong with the image.setImageDrawable syntax. When I run my app it crashes.
Try above and make sure the image exists with the exact name.