我在这里有点困惑。
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.bugs_list_item, itemCursor,
new String[] {db.KEY_ROWID, db.BUGS_DATE, db.BUGS_DESCRIPTION},
new int[] {R.id.bug_id, R.id.bug_date, R.id.bug_description});
这基本上向我显示了一个带有日期和描述但没有 id 的 ListView(我只是用空格代替 id)。_id 字段是主键,它是一个整数。
看看它在 img 上的样子
XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/bug_id"
android:layout_width="5dip"
android:layout_height="wrap_content"
android:padding="3dip"
>
</TextView>
<TextView
android:id="@+id/bug_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:gravity="right"
>
</TextView>
<TextView
android:id="@+id/bug_description"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:padding="3dip"
android:gravity="right"
>
</TextView>
</TableRow>
</TableLayout>
创建表查询:
BUGS_CREATE = "CREATE TABLE bugs (_id INTEGER NOT NULL PRIMARY KEY, date DATE DEFAULT (DATETIME('NOW')) NOT NULL, description TEXT) ";