Search code examples
c#androidxamarinxamarin.androidxamarin-studio

Is there a way to search for a TextView dynamically? (Xamarin)


I'm trying to find the resource id of a textView dynamically. I need it to find each TextView in the layout according to each name that is input.

Here's as far as I have gotten:

        String test = "t12";
        //Just an idea I had on how to get it.Doesnt work
        var r = (TextView)test;
        TextView t = FindViewById <TextView>(Resource.Id.r);

Any help would be appreciated... :)


Solution

  • The following code works:

            String test = "t12";
            int resID = Resources.GetIdentifier(test, "id", PackageName);
            var k = (TextView)FindViewById(resID);
            k.Text = "Hello World";