Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Get ID of variable resource

$
0
0

I've found several posts about getting the ID of a resource by name. I have tried two different methods, and never one works.

//This one returns 0:
int varInt = Resources.GetIdentifier ("background1", "drawable", PackageName);

//This one returns 'object reference not set':
int varInt = (int)typeof(Resource.Layout).GetField("background1").GetValue(null);

Am I doing something wrong? I have several drawable folders (i.e. drawable-land, drawable-port, etc.), but I tried using drawable-land in the above code and it still returns 0. Thanks!


Viewing all articles
Browse latest Browse all 204402

Trending Articles