2016-10-01 54 views
0

我試圖動態地查找textView的資源ID。我需要它根據輸入的每個名稱在佈局中查找每個TextView。有沒有辦法動態地搜索TextView? (Xamarin)

下面是據我已經得到了:

 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); 

任何幫助,將不勝感激... :)

+0

添加您的編輯作爲答案並接受它。 – Cheesebaron

回答

0

下面的代碼工作:

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

不能解析這樣的......

String test =「t12」;

var r =(TextView)test;

嘗試像這樣...

的TextView的TextView =新的TextView(本);

textView.Text =「some text」;

相關問題