I have 4 buttons that when click starts a new activity class. This works fine using switch case. But I want a drawable to show in an Image View based on which button was clicked. I’m not sure how to do this. Could someone give me and idea of how to research this for some sample code.
case R.id.button1:
intent = new Intent(Gallery.this, Photos.class);
intent.putExtra("iv", R.drawable.photo1);
break;
case R.id.button2:
intent = new Intent(Gallery.this, Photos.class);
intent.putExtra("iv", R.drawable.photo2);
break;
This works as far as switching to the Photos activity but the drawable doesn’t show in the Imagae View. I have this code in the Photos Activity.
iv = (ImageView)findViewById(R.id.photo);
Bundle extras = getIntent().getExtras();
extras.getInt("iv");
I do not get any errors I just don’t have the photo showing up.
Thank you for any help you can give.
Looks like the only thing you’re missing is the call to actually set the image – everything else looks fine. Make the last lines more like:
You were most of the way there. Android has a great set of tutorials for coming up to scratch with all of the basic view components.