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); //S
Solution 1:
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,
ImageViewv= (ImageView)findViewbyId(R.id.img);
StringbackgroundImageName= 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
}
Solution 2:
You can set the name ussing tag.
imageView.setTag("any name")
And retrieve the value using
String imageNameName = (String) imageView.getTag();
Solution 3:
ImageViewimg= (ImageView) findViewById(R.id.imageView);
StringimageName= img.getContentDescription();
Solution 4:
Couldn´t you use something like this?
ImageViewv= (ImageView)findViewbyId(R.id.img);
if(R.id.someId == v.getId())
{
//do something
}
else{
//do something
}
It´s easier than use resources' names.
Post a Comment for "How To Get The Image Name Of The Imageview In Android?"