Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the image name of the ImageView in Android?

I have an imageview in android . I want to get the name of the image which is set in the in the imageview. How can I do that ?

ImageView v = (ImageView)findViewbyId(R.id.img);
//String name = findImageName(v);
if( name.equals(a))
{
   //do something
} 
else{
   //do something
}
like image 915
osimer pothe Avatar asked Jul 27 '15 10:07

osimer pothe


People also ask

Which method and attribute is used to set image of ImageView in Android?

src: src is an attribute used to set a source file or you can say image in your imageview to make your layout attractive.

What is ImageView code?

ImageView class is used to display any kind of image resource in the android application either it can be android. graphics. Bitmap or android. graphics.

Can ImageView display video?

ImageView is a control which display image on android and support RGB image, so setting the data of ImageView every period can generate dynamic video.


1 Answers

For this first of all you need to set a tag for your ImageView

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageview1" 
    android:background="@drawable/bg1"
    android:tag="bg1"/>

Now get the image name currently set on your ImageView by doing the following,

ImageView v = (ImageView)findViewbyId(R.id.img);
String backgroundImageName = String.valueOf(v.getTag());

and this should return the image tag name which is "bg1".

Now compare the tag names or use it for further process

if( backgroundImageName.equals(bg1))
{
   //do something
} 
else{
   //do something
}
like image 127
Prokash Sarkar Avatar answered Oct 21 '22 09:10

Prokash Sarkar