あなたが求めていることを正確に行う方法はわかりませんが、ここに2つの選択肢があります:
1.整数の配列を作成し、配列の各要素を異なるビューID値に割り当てます
int[] ids = new int[arrayList.size()];
ids[0] = R.id.view0;
ids[1] = R.id.view1;
ids[2] = R.id.view2;
//...ids[n] = R.id.viewN; where n goes up to arrayList.size()
for (int i : ids){
((TextView)dialog.findViewById(ids[i])).setText(arrayList.get(i));
}
TextView
より動的なものが必要な場合は、すべての行が必要なため、上記の方法ではポイントが無効になることに注意してください。
2.TextViews
レイアウト xml でタグ付けしandroid:tag="prefix0"
ます。たとえば、それぞれのTextViews
. ループの前に、レイアウトの親ビューを見つけてfindViewWithTag
から、ループ内でそのビューのメソッドを使用しfor
ます。あなたのコードからDialog
、カスタム レイアウト xml を使用していると思われるので、最初にその親を見つけます。
ViewGroup parent = dialog.findViewById(R.id.parent); //or whatever the name of your parent LinearLayout/RelativeLayout/whatever is
String commonPrefix = "prefix"; //or whatever you've tagged your views with
for (int i=0; i<arrayList.size(); i++){
TextView t = (TextView) parent.findViewWithTag(commonPrefix+i);
t.setText(arrayList.get(i));
}