Strange request here, but is there any way you set an imageview to hold the same drawable as another imageview by getting it from the original imageview. what i mean is:
ImageView image1 = new ImageView(this);
image1.setimageResource(R.drawable.blah1);
ImageView image2 = new ImageView(this);
//now i want something like this, which doesn't work. i want to get it from image1
image2.setImageResource(image1.getDrawable());
so please how can i achieve this from image1?.. Thank you :)
If you don't want to set image to xml file and show image programmatically then you need to use this method. For E.g. You set image in xml which showing ON Switch now when you click ON Button its should be set to OFF Switch so in that case you can set using this setImageResource() programmatically.
There's no differences, except default style.
You can make a view clickable, as a button, by adding the android:onClick attribute in the XML layout. For example, you can make an image act like a button by adding android:onClick to the ImageView .
Use setImageDrawable
instead of setImageResource
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With