开发者

How to check which image is set to the activity's view?

How can I check what image is 开发者_如何学Pythonon my activity (programmatically)? I want to make a condition: if I have lets say img1, then I want to show a Toast "img1", and if I have img2, then I want to show a Toast "img2". I know there is something like setImageDrawable(getResources().getDrawable(R.drawable.img2), which does setting an image.


you can use the setTag function associated with a view to hold this information, as in view.setTag("img1") and you can get back the value as in (String)view.getTag()


you want to test if your imageView contains an image, then u want to set another

use this if it helps

if(imgView.getDrawable().equals(this.getResources().getDrawable(R.id.img1))) {
     //affiche your Toast Here ... Toast ( "img1 displayed ..").show();
     Toast.makeText(this,"image 1 dispayed ...",3000).show();
}
else if(imgView.getDrawable().equals(this.getResources().getDrawable(R.id.img2))) {
     //affiche your Toast Here ... Toast ( "img2 displayed ..").show();
     Toast.makeText(this,"image 2 dispayed ...",3000).show();
}

is that what you want to do ??

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜