我在這裏有點困惑。如何從表中獲取_id字段並將其放入ListView中
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) ";
所以,你想顯示項目ID與列表視圖NA? – Praveenkumar 2011-12-19 13:34:15