我正在使用数据库,将光标移出,然后使用simplecursoradapter填充列表视图。我似乎无法弄清楚为什么应用程序崩溃创建一个新的simplecursoradapter。我的光标包含在一个单独的对象中。我通过这个类中的数据变量来引用它。simplecursoradapter无法正常工作
String[] columns = new String[] {"item", "quantity", "days"};
int[] to = new int[] { R.id.nametext, R.id.quantitytext, R.id.dayslefttext};
SimpleCursorAdapter sCA = new SimpleCursorAdapter(this, R.layout.itemrow, data.listCursor, columns, to);
listView1.setAdapter(sCA);
simplecursoradapter在构造函数中传递给它的信息是做什么的?是格式错误的参数之一吗?下面是每一行简单的XML文件,我使用的只是看到,如果这个工程:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Loading Screen"
android:id="@+id/nametext"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Loading Screen"
android:id="@+id/quantitytext"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Loading Screen"
android:id="@+id/dayslefttext"/>
</LinearLayout>
这是我如何加载光标:
listCursor = myDataBase.query(ITEMS_TABLE, null, "location" +" = ?", new String[]{IN_SPECIAL_LIST}, null, null, "item");
我想不出什么问题是。我通过一些调试运行了这个,当我创建新的simplecursoradapter时会出现问题。
您是否看过Logcat输出?抛出什么异常? – 2011-04-04 10:35:36