我想用for循环中的“String row”变量填充我的“String [] collect”数组,我不知道如何正确地做到这一点!当数组被填充时,我想将它显示为带有textview的字符串。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
List<double[]> lokal = readCsv(getApplicationContext());
for (double[] sor : lokal) {
for (int i = 0; i < sor.length; i++) {
mean(sor);
String row = Double.toString(mean(sor));
String[] collect = new String[] { row };
}
}
getActionBar().setDisplayHomeAsUpEnabled(true);
TextView textView = new TextView(this);
textView.setTextSize(30);
textView.setText(collect);
setContentView(textView);
}
答案 0 :(得分:3)
您每次通过String Array
创建一个新的loop
。使用ArrayList
因为它们可以具有动态尺寸并尝试类似
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
List<double[]> lokal = readCsv(getApplicationContext());
ArrayList<String> array = new ArrayList<String>(); // initialize ArrayList here, may want to declare as class variable
for (double[]sor : lokal) {
for(int i=0; i<sor.length; i++) {
mean(sor);
String row = Double.toString(mean(sor));
array.add(row); // add your String to it here
将所有String
放在一起只是迭代它们。像
String result = ""
for (int c=0; c<array.size(); c++)
{
String curString = array.get(c);
result.concat(curString);
}
textview.setText(result);
如果不起作用,您可以使用
result = result + curString;
as“+”是String
s