我试图将数组列表中的每个值显示给我手动创建或固定的textView的每个textView
totalCardPerPage = 30;
cardNumber = 1;
//looping to determine textView id in my xml
for(int x=1;x<=totalCardPerPage;x++){
//textView id
textId = "text"+cardNumber;
int id = getResources().getIdentifier(textId, "id", "com.example.radioexample");
TextView currcell = (TextView) findViewById(id);
//get array size
int arrayListSize = arrayListPage1.size();
//looping to show each value in textView
for(int y=0; y<=arrayListSize; y++){
currcell.setText(arrayListPage1.get(y).toString);
currcell.setBackgroundColor(Color.RED);
}
cardNumber++;
}
问题是循环显示 textView 中的每个值。
运行此代码时出现错误
我通过 arraylist 中的循环实现了这一点,数组中的所有值仅聚集在一个 textView 中
如果我的数组中有5个值,每个值都会显示在每个textView中。
例如,
arraylist {a,b,c,d,e};
text1.setText(a);
text2.setText(b);
text3.setText(c);
text4.setText(d);
text5.setText(e);
有人知道怎么做吗?
谢谢
最佳答案
这个问题很旧但是
是 Google 搜索中的第一个结果。
要完成这项工作,您必须在循环中调用 arraylist 的所有值,并在特殊的 Textview 上设置,如下代码:
如果你有这个数组列表和 TextView
arraylist {a,b,c,d,e};
TextView []tv=new TextView[5];
tv[0]=(TextView)findViewById(R.id.____);
tv[1]=(TextView)findViewById(R.id.____);
tv[2]=(TextView)findViewById(R.id.____);
tv[3]=(TextView)findViewById(R.id.____);
tv[4]=(TextView)findViewById(R.id.____);
//循环将数组列表加载到特殊的 Textview 中
for(int i=0;i<arraylist.size();i++)
{
tv[i].setText(arraylist.get(i).toString());
}
关于java - 将 arraylist 中的每个值显示到每个 textView Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23222654/