机器人findViewbyId具有变异串 [英] Android findViewbyId with a variant string

查看:91
本文介绍了机器人findViewbyId具有变异串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TextView textView1= (TextView) dialog.findViewById(R.id.textView1);

我倒要创建这样的:

I d like to create something like this:

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

我怎么能做到这一点?

how can i do that?

张国荣

推荐答案

请参阅<一href="http://developer.android.com/reference/android/content/res/Resources.html#getIdentifier%28java.lang.String,%20java.lang.String,%20java.lang.String%29"><$c$c>getIdentifier.基本上,你想是这样的:

See getIdentifier. Basically, you want something like:

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

这篇关于机器人findViewbyId具有变异串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆