Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get associated image (Drawable) in ImageView android

I have set an image to an ImageView control in android:

iv.setImageResource(R.drawable.image1);

I want to get this associated Drawable, looks like:

Drawable myDrawable = iv.getImageResource(); //wrong
like image 361
thenosic Avatar asked Sep 01 '11 06:09

thenosic


People also ask

How to get Drawable of ImageView in Android?

This is an easy approach if you can use the view's id member variable: just store the R. drawable id using v. setId(). Then get it back with v.

How do I find the drawable image ID?

drawable id in the view's id: use v. setId() . Then get it back with v. getId() .

How to put image in Drawable XML file?

Step 1: In this method first of all in your system find your required images and copy the image as we do normally. Step 2: Then open the Android Studio go to the app > res > drawable > right-click > Paste as shown in the below figure. Step 3: Then a pop-up screen will arise like below.


1 Answers

You can get the drawable like

Drawable myDrawable = iv.getDrawable();

You can compare it with a drawable resource like

if(iv.getDrawable()==getResources().getDrawable(R.drawable.image1)){
    //do work here
}
like image 104
A.J. Avatar answered Oct 15 '22 02:10

A.J.