ImageView, how do you getSrc programatically for a drawable?

109 Views Asked by At

So for an ImageView there's a imageView.getBackground() that returns the background drawable. Is there a way to get the src drawable programatically like this?

Here is a small example of what I mean:

snippet of main.xml

...
<ImageView
    android:id="@+id/main_iv"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:src="@drawable/imageSrc"
    android:background="@drawable/imageBG" />
...

Java

public class ActivityMain extends Activity {
    ImageView iv;
    ...

    ...
    @Override
    public void onCreate(Bundle sIS){
        super.onCreate(sIS);
        setContentView(R.layout.main);
        iv = (ImageView)findViewById(R.id.main_iv);
        Drawable bg = iv.getBackground();
        // Drawable source = iv.getSource(); but this method does not exist
    }
...
}
1

There are 1 best solutions below

0
On BEST ANSWER

Call getDrawable() to get the Drawable in an ImageView.