1

Finding a resource in your layout is easy if you know the id:

LinearLayout l = FindViewById<LinearLayout>(Resource.Id.linearLayout1); 

but say I have

String id = "linearLayout1"; 

How can I access the resource IDs and "find" the one I'm looking for?

2 Answers 2

2
int resID = Resources.GetIdentifier(resourceName, "id", PackageName); 

Source

Sign up to request clarification or add additional context in comments.

Comments

1

You can use this: Resources#getIdentifier()

String id = "linearLayout1"; int resourceId = getResources().getIdentifier(id, "id", getPackageName()); 

Edit:

I didn't see the Xamarin tag. I am not familiar with Xamarin, but as far as I know, it mimics the Android API, so there should be a similar method available for that.

1 Comment

Just had to tweak it for Xamarin, but yep, this is just what I was looking for.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.