Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setImageResource for an ImageView from another ImageView

Tags:

android

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 :)

like image 900
irobotxx Avatar asked Jan 13 '12 01:01

irobotxx


People also ask

What is the role of setImageResource?

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.

What is the difference between ImageView and Imagebutton?

There's no differences, except default style.

Can ImageView be clickable?

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 .


1 Answers

Use setImageDrawable instead of setImageResource

like image 124
ᅙᄉᅙ Avatar answered Nov 16 '22 02:11

ᅙᄉᅙ