如何在Android的打印nextline数组元素上的TextView

人气:1,075 发布:2022-09-11 标签: android

问题描述

大家好,我有一个二维数组。我打印这个阵列上的文本视图的元素。但我的所有元素来了一个row.I想要元素之间换行。我的code在下面给出我的二维数组是:

hello everyone i have a 2D array. I am printing the elements of this array on a text View. But my all elements are coming in one row.I want line break between elements. my code is given below and my 2D array is:

table[][]={{1,2,3,4,5,6,7,8},{8,7,6,5,4,3,2,1}}

for(i=0;i<8;i++)
for(j=0;j<2;j++)
{
text = new TextView(this);
text.setText(""+table[j][i]);
}

像这样的

和我得到的输出:

and i am getting output like this:

{1,8,2,7,3,6,4,5,5,4,6,3,7,2,8,1}

但我想这样的输出:

but i want output like this:

1,8
2,7
3,6
4,5
5,4
6,3
7,2
8,1 

任何帮助将是AP preciated。

any help would be appreciated.

推荐答案

我会建议不要在回路中产生的TextView。 只要使用相同的看法:

I would suggest not to create TextView in the loop. Just use same view:

table[][]={{1,2,3,4,5,6,7,8},{8,7,6,5,4,3,2,1}}
text = new TextView(this);

for(i=0;i<8;i++) {
    for(j=0;j<2;j++) {
        text.append(""+table[j][i] + "\n");
    }
}

214