如何在Android中获取ImageView的图像名称? [英] How to get the image name of the ImageView in Android?

查看:193
本文介绍了如何在Android中获取ImageView的图像名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在android中有一个imageview。我想获取在imageview中设置的图像的名称。我怎样才能做到这一点 ?

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
}


推荐答案

首先,你需要设置一个标签对于你的ImageView

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"/>

现在通过执行以下操作获取ImageView上当前设置的图像名称,

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());

这应该返回图片标记名称bg1

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
}

这篇关于如何在Android中获取ImageView的图像名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆