简体   繁体   中英

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... :)

The following code works:

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

You cannot parse like this......

String test = "t12";

var r = (TextView)test;

Try like this...

TextView textView = new TextView(this);

textView.Text = "some text";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM