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
}
src: src is an attribute used to set a source file or you can say image in your imageview to make your layout attractive.
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.
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.
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
}
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