-2
String hallo = "blabla " + "jojo " + "\n" + "doj " + "drasl " +"\n";
InputStream is = new ByteArrayInputStream(hallo.getBytes());
BufferedReader in = new BufferedReader(new InputStreamReader(is));

String reader;
    while ((reader = in.readLine()) != null) {
    String[] RowData = reader.split(" ");
    String eitt = RowData[0];
    String tvo = RowData[1];

我有一个与字符串格式相同的hallo字符串,只是我不知道有多少行。我正在尝试将信息放在表格布局中(或者最方便的方式)。

如何textview根据需要在表格布局中自动创建确切数量的窗口,并自动输入我的字符串值?

顺便说一句,如果重要的话,textview它在布局内。scrollview

4

1 回答 1

0

使用以下代码

String hallo = "blabla " + "jojo " + "\n" + "doj " + "drasl " + "\n";
InputStream is = new ByteArrayInputStream(hallo.getBytes());
BufferedReader in = new BufferedReader(new InputStreamReader(is));
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearLayout);

String line;
try {
    while ((line = in.readLine()) != null) {
        String[] RowData = line.split(" ");
        String eitt = RowData[0];
        String tvo = RowData[1];

        TextView textView = new TextView(this);
        textView.setText(line);

        linearLayout.addView(textView);
    }
} catch (IOException e1) {
    e1.printStackTrace();
}

使用这个 xml 布局

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
    </LinearLayout>

</ScrollView>
于 2012-11-01T11:37:19.737 回答