4

I have an ImageButton, and I want to use the Image associated with in the OnClick event.

I found this: Android ImageButton - determine what resource is currently set

But I wonder is there any built in way to find the resourceid of the image in an ImageButton in this two cases: 1. The android:src was set in the xml and never changed. 2. The Image was changed in code.

Thank You!

Community
  • 1
  • 1
borod
  • 43
  • 1
  • 4

1 Answers1

3

This isn't possible.

I'd listen to Mark:

just use setTag() and getTag() to associate and retrieve custom data for your ImageView.

Community
  • 1
  • 1
Matthew
  • 44,826
  • 10
  • 98
  • 87
  • Thank you Matthew, In the first case I am sure it is possible at least in theory to pars the main.xml isn't it? am I the only person who needs this feature? I am new to Android so perhaps I do not understand the concept behind this, but why isn't there an easy way to get the attributes? – borod Mar 06 '11 at 10:18
  • getting the attributes from xml is not difficult--but then what do you do when the attributes change? You'll have to keep that information in a tag. Why have two different code paths (xml and setBitmapResource). At that point you might as well just set your resource in Java code and at the same time set the tag. – Matthew Mar 06 '11 at 10:23
  • hmm. Interesting, you have convinced me for the time being :). Thank you for the help and the quick replay :) – borod Mar 06 '11 at 10:28