可滚动的TableLayout android

时间:2015-05-13 18:42:42

标签: android sqlite scrollview tablelayout

我的app有问题。我有SQLite数据库,它工作正常。我有用户选择日期范围的活动,当用户点击按钮时应该打开带有数据的表。当我没有使用ScrollView时,它工作。现在它给出了太多孩子的错误。我是初学者,你能帮我解决一下吗? 我的代码.xml:

<ScrollView
   android:id="@+id/scroll"
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:background="#00ffedff"
   android:fadeScrollbars="false"
   android:scrollbarAlwaysDrawHorizontalTrack="true"
   android:scrollbarAlwaysDrawVerticalTrack="true"  >

<TableLayout
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:orientation="horizontal"
    android:stretchColumns="1"
    android:background="#73ffffff"
    android:scrollbars="vertical"
    android:isScrollContainer="true"
    android:scrollbarAlwaysDrawVerticalTrack="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tableLayout">
    <TableRow
        android:id="@+id/nos"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent">
        <TextView/>
        <TextView/>
        <TextView/>
    </TableRow>
  <TableLayout/>
<Scrollview/>

的java:

 String query = "SELECT * from  Dienasgramata WHERE Datums BETWEEN'" + min +    "'  AND  '" + max + "'  ";
    Log.d("MyQuery", query);


  Cursor c = database.rawQuery(query, null);
    int count = c.getCount();
    c.moveToFirst();



    for (Integer j = 0; j < count; j++) {
        tableRow = new TableRow(getApplicationContext());
        textView1 = new TextView(getApplicationContext());
        textView1.setText(c.getString(c.getColumnIndex("Date")));
        textView1.setTextColor(Color.BLACK);
        ......

        textView1.setPadding(20, 20, 20, 20);
        ......
        tableRow.addView(textView1);
       ......
        tableRow.addView(tableLayout);



        c.moveToNext() ;



    }
   c.close();


    setContentView(tableLayout);

    database.close();
}

1 个答案:

答案 0 :(得分:0)

数据库可能包含太多记录,平板电脑布局会消耗太多内存。切换到RecyclerView