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.
How to do that?
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
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);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…