我试图将数组中的每个值显示给我手动创建或修复的每个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中显示每个值的循环。
我运行这段代码时出错了
我在数组中实现了循环,数组中的所有值都集中在一个textView中。
如果我的数组中有5个值,那么每个值都将显示在每个textView中。
例如,
arraylist {a,b,c,d,e};
text1.setText(a);
text2.setText(b);
text3.setText(c);
text4.setText(d);
text5.setText(e);有人知道怎么做吗?
谢谢
发布于 2016-04-10 07:36:57
这个问题由来已久,BUT是谷歌搜索的第一个结果。
为了完成这项工作,您必须在一个循环中调用arraylist的所有值,并在特殊的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());
}https://stackoverflow.com/questions/23222654
复制相似问题