[英]Is there a way to search for a TextView dynamically? (Xamarin)
I'm trying to find the resource id of a textView dynamically. 我正在尝试动态查找textView的资源ID。 I need it to find each TextView in the layout according to each name that is input. 我需要它根据输入的每个名称在布局中找到每个TextView。
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"; 字符串测试=“ t12”;
var r = (TextView)test; var r =(TextView)test;
Try like this... 这样尝试...
TextView textView = new TextView(this); TextView textView =新的TextView(this);
textView.Text = "some text"; textView.Text =“一些文本”;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.