我刚刚开始与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