【问题标题】:Is there a way to search for a TextView dynamically? (Xamarin)有没有办法动态搜索 TextView? (Xamarin)
【发布时间】:2016-10-01 20:40:52
【问题描述】:

我正在尝试动态查找 textView 的资源 ID。我需要它根据输入的每个名称在布局中找到每个 TextView。

这是我所得到的:

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

任何帮助将不胜感激... :)

【问题讨论】:

  • 将您的编辑添加为答案并接受它。

标签: c# android xamarin xamarin.android xamarin-studio


【解决方案1】:

以下代码有效:

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

【讨论】:

    【解决方案2】:

    你不能这样解析......

    字符串测试 = "t12";

    var r = (TextView)test;

    试试这样...

    TextView textView = new TextView(this);

    textView.Text = "一些文字";

    【讨论】:

      猜你喜欢
      • 2017-04-02
      • 1970-01-01
      • 2019-09-27
      • 2011-03-12
      • 2010-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多