如何获得的ImageView源,以改变它呢? [英] how to get the source of ImageView in order to change it?

查看:165
本文介绍了如何获得的ImageView源,以改变它呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,改变ImageView的资源不只是使用大不了 myImageView.setImageResource(mynewImageDrawable)

I know that changing the ImageView resource is not big deal just using myImageView.setImageResource(mynewImageDrawable)

但我想要做的是改变之前,检查当前的ImageSource。

but what I want to do is to check the current ImageSource before changing it.

基本上,我想用imageViews实现我自己组单选按钮。所以每任何的ImageView点击时,oncliked事件方法会改变我的组的图像资源。

basically, I want to implement my own group radio buttons using imageViews. so every time any imageView is clicked, the oncliked event method will change the Image Resources of my group.

和对不起我的英文不好。

and sorry for my poor English.

问候, redsea

regards, redsea

推荐答案

没有 getDrawableId 功能,所以你需要做的是这样设置的标签为的ImageView 。例如,设置绘制ID为标签的的ImageView 所以你可以只得到来自标签的绘制ID。

There is no getDrawableId function so you'll need to do something like set a tag for the ImageView when you change its drawable. For instance, set the drawable id as a tag for the ImageView so you could just get the drawable id from the tag.

我会说90%的时间,你的看法不会对他们有任何标记,所以最简单的方法是假设你的标签是唯一的标签:

I'd say 90% of the time, your views wont have any tag on them, so the easiest way is to assume your tag is the only tag:

myImageView.setTag(R.drawable.currentImage);    //When you change the drawable
int drawableId = (Integer)myImageView.getTag(); //When you fetch the drawable id

如果我已经有一个标签贴在我看来

机器人视图可以承载多个标签同时,只要它们具有一个唯一的标识符。你需要创建一个唯一的ID 资源加上它作为第一个参数 setTag 方法调用。离开code是这样的:

What if I already have a tag on my view

Android views can host multiple tags at the same time, as long as they have a unique identifier. You'd need to create a unique id resource and add it as the first argument to the setTag method call. Leaving the code like this:

myImageView.setTag(R.id.myTagId, R.drawable.currentImage); //Set
int drawableId = (Integer)myImageView.getTag(R.id.myTagId);

这篇关于如何获得的ImageView源,以改变它呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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