TextView textView1= (TextView) dialog.findViewById(R.id.textView1);
我想创建这样的东西:
for (int i=0; i<100; i++) { TextView textView= (TextView) dialog.findViewById(R.id.textView+i); }
我怎样才能做到这一点?
莱斯利
请参阅getIdentifier
。 基本上,你想要的东西:
for (int i=0; i<100; i++) { int resId = getResources().getIdentifier("textView" + i, "id", getPackageName()); TextView textView = (TextView) dialog.findViewById(resId); }