Let’s say that I have a drawable :
foo.png
At certain point in my program, it receives one of two possible string keys: “img_foo1” or “img_foo2”, which I want to use to retrieve the same “foo” drawable.
So I tried accessing the drawable from other two resources in the way of:
<drawable name="img_foo1">@drawable/foo</drawable>
<drawable name="img_foo2">@drawable/foo</drawable>
Then I thought that I could use getResources().getIdentifier() with those key names, however that gives me the ID of img_foo1, and img_foo2, but not the ID of drawable foo.
Is there any way I could get the resource ID to which these resources are referencing?
edit:
The reason I do this, is because I receive these keys from an external source from which I have no control. The only thing that I can do, is somehow map the known keys to the corresponding drawables to draw the correct image (because the same image may be used by different keys).
I could achieve this with an static collection which I can initialize with the app, however I’m trying to help me with the resources instead.
Use
getValue(), passingfalsefor the last parameter. I guess you’ll now get the reference to@drawable/fooin theTypedValuewhose id you can now retrieve. I haven’t tried it; let me know if you give it a shot.