我剛剛開始與Android和我嘗試我的第一個測試應用程序,但我有點卡住了。Android從SQLite綁定到圖庫
我有一個SQLite數據庫,並且用戶正在選擇一張圖片和一個對此的引用,並且一個簡短的描述被存儲在數據庫中。 這一切都工作正常,現在我想要將圖像從數據庫綁定到一個畫廊,但我有點困惑,我如何做到這一點。
我的佈局XML如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Gallery
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Weeksgallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<Button android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text1"
android:layout_marginLeft="10dip"
android:text="Take a Picture"
android:onClick="TakePicture" />
</LinearLayout>
我想用一個按鈕下方
我在走廊上創建功能我有以下幾點:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mDbHelper = new DbAdapter(this);
mDbHelper.open();
Cursor cur = mDbHelper.fetchDaysImages();
//array of fields to display
String[] from = new String[] { mDbHelper.KEY_ROWID,mDbHelper.KEY_PICREF};
int[] to = new int[] { R.id.Weeksgallery };
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter images = new SimpleCursorAdapter(this,
R.layout.main, cur, from, to);
setListAdapter(images);
mDbHelper.close();
}
我現在用的是記事本教程爲例,我的課程擴展了ListActivity。
當我運行它,我得到的錯誤
您的內容必須有一個ListView其id屬性爲「android.R.id.list」
我假設我使用錯誤的綁定類型,但我似乎無法找到任何告訴我如何從sqlite數據庫綁定到圖庫的地方。 我也想在圖庫中添加對rowId的引用,所以當圖片被點擊時它會打開相關頁面(所以它可以顯示消息)
任何人都可以幫忙嗎?
感謝
貝克斯
這些CAPS真的讓我覺得更傾向於幫助.... – 2010-10-19 09:39:34
對不起,他們在那裏使它突出,所以有人會看到它,也許應該用粗體代替..現在已經刪除它們擺弄,並得到文本格式正確 – Bex 2010-10-19 09:40:34