I have a layout with 1 textview, 1 imageview and 1 button. And I have 5 pictures in drawable. Their names like image1, image2, image3... When I click button, button change random picture in drawable("image" + rand. numbers method) But I want to print changed image name to textview. How can I do it? *Briefly; Button Funcion: First print existing image > then change new random image. **I'm sorry for bad grammer..
public void onClick(View v) {
ImageView img=(ImageView)findViewById(R.id.imageView1);
Random rand = new Random();
int rndInt = rand.nextInt(5) + 1;
String drawableName = "image"+ rndInt;
int resID = getResources().getIdentifier(drawableName, "drawable", getPackageName());
img.setImageResource(resID);
};