I have a image called(my_image.png) in my Drawable-mdpi folder.
my android application interacts with a webservice. It might send back “my_image”. My android application should load up this image.
I am using Monodroid and I tried this
int abc = Resources.GetIdentifier("my_image","drawable",null);
Yet the result is always "0". When it should be(from the resource file)
// aapt resource value: 0x7f020000
public const int my_image = 2130837504;
Looking around and the android way seems to be similar
int i = this.getResources().getIdentifier("txt_asecondtext", "strings", this.getPackageName());
I tried passing in the package name instead of null but that did nothing.
The problem is twofold:
Resources.GetIdentifier()call, and not usenull.The simple way to ensure you get the correct package name is to use the Android.Content.Context.PackageName property:
If you don’t want to/can’t use
Context.PackageName, then look at the build output, in e.g. theobj\Debug\android\AndroidManifest.xmlfile, and use the value of the/manifest/@packageattribute value. For example,AndroidManifest.xmlmay contain:Thus, you could instead use:
For
monodroid@lists.ximian.comsubscribers, see the How to use Resources.GetIdentifier() thread, and the followup message.