【问题标题】:Android findViewbyId with a variant string带有变体字符串的 Android findViewbyId
【发布时间】:2011-07-13 21:14:01
【问题描述】:
TextView textView1= (TextView) dialog.findViewById(R.id.textView1);

我想创建这样的东西:

for (int i=0; i<100; i++) {
   TextView textView= (TextView) dialog.findViewById(R.id.textView+i);
}

我该怎么做?

莱斯利

【问题讨论】:

    标签: android


    【解决方案1】:

    getIdentifier。基本上,你想要这样的东西:

    for (int i=0; i<100; i++) {
       int resId = getResources().getIdentifier("textView" + i, "id", getPackageName());
       TextView textView = (TextView) dialog.findViewById(resId);
    }
    

    【讨论】:

      猜你喜欢
      • 2011-06-19
      • 1970-01-01
      • 1970-01-01
      • 2016-08-06
      • 1970-01-01
      • 2014-09-10
      • 1970-01-01
      • 2016-10-09
      • 1970-01-01
      相关资源
      最近更新 更多