View v中显示的Drawable的getResource ID

时间:2011-10-27 21:15:54

标签: android drawable

我正在尝试做类似的事情,我也有问题。我在屏幕上使用动态ImageViews。 Per OnClickListener我正在更改视图的资源ID。

我希望能够分辨出被点击的视图中显示的Drawable的资源ID是什么。

OnClickListener(View v)
{
ImageView temp=(ImageView)v;
//I Can change Image Resource of the Clicked View with this->

temp.setImageResource(R.drawable.picture_1);

//but how can I find out what Resource ID the Drawable has that is  displayed in the View?
//(I'm searching for a method   ->temp.getImageResource();)

}

OnClickListener(View v) { ImageView temp=(ImageView)v; //I Can change Image Resource of the Clicked View with this-> temp.setImageResource(R.drawable.picture_1); //but how can I find out what Resource ID the Drawable has that is displayed in the View? //(I'm searching for a method ->temp.getImageResource();) } 谢谢你的帮助!菲利普

1 个答案:

答案 0 :(得分:1)

这样的事情应该有效

temp.setImageResource(R.drawable.picture_1);
temp.setTag(R.drawable.picture_1);

然后获取资源ID

temp.getTag();