开发者

Android findViewbyId with a variant string

开发者 https://www.devze.com 2023-03-20 12:31 出处:网络
TextView textView1= (TextView) dialog.findViewById(R.id.textVi开发者_开发知识库ew1); I d like to create something like this:
TextView textView1= (TextView) dialog.findViewById(R.id.textVi开发者_开发知识库ew1);

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?

Leslie


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

精彩评论

暂无评论...
验证码 换一张
取 消