simplecursoradapter不工作 [英] simplecursoradapter not working
问题描述
我使用一个数据库,获得了它的一个光标,然后用simplecursoradapter来填充列表视图。我似乎无法找出原因,应用程序崩溃上创建一个新的simplecursoradapter。我的光标被包含在一个单独的对象。我通过数据变量在这个类中对它的引用。
的String []列=新的String [] {项,量,日};
INT []到=新INT [] {R.id.nametext,R.id.quantitytext,R.id.dayslefttext};
SimpleCursorAdapter SCA =新SimpleCursorAdapter(这一点,R.layout.itemrow,data.listCursor,列,到);
listView1.setAdapter(SCA);
什么是simplecursoradapter做传递给它在其构造的信息?在错误格式的参数之一?下面是我使用只是看看,如果这个工程的每一行简单的XML文件:
< XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT>
<的TextView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=载入画面
机器人:ID =@ + ID / nametext
/>
<的TextView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=载入画面
机器人:ID =@ + ID / quantitytext
/>
<的TextView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=载入画面
机器人:ID =@ + ID / dayslefttext
/>
< / LinearLayout中>
下面是我如何加载光标:
listCursor = myDataBase.query(ITEMS_TABLE,空,位置+=?,新的String [] {} IN_SPECIAL_LIST,NULL,NULL,项目);
我无法弄清楚的问题是什么。我跑这通过一些调试时发生II创建新simplecursoradapter的问题。
谢谢!
myDataBase.query(ITEMS_TABLE,空,...
这null是你的问题
应该有
新的String [] {YOURID AS _id,项,量,天}
SimpleCursorAdapter需要_id列
YOURID可以ROWID(ROWID作为_id),或从你的数据库的任何int或长ID
I am using a database, getting a cursor out of it and then using a simplecursoradapter to populate a listview. I can't seem to figure out why the app crashes on creating a new simplecursoradapter. My cursor is contained in a singleton object. I have a reference to it through the data variable in this class.
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);
What does the simplecursoradapter do with the information passed to it in its constructor? Is one of the parameters in the wrong format? Here is the simple xml file for each row that I am using to just see if this works:
<?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>
Here is how I load the cursors:
listCursor = myDataBase.query(ITEMS_TABLE, null, "location" +" = ?", new String[]{IN_SPECIAL_LIST}, null, null, "item");
I can't figure out what the problems is. I ran this through some debugging and the problem occurs when I I create the new simplecursoradapter.
Thanks!
myDataBase.query(ITEMS_TABLE, null, ...
this null is your problem
there should be
new String[] {"YOURID AS _id", "item", "quantity", "days"}
SimpleCursorAdapter need _id column
YOURID could be ROWID (ROWID as _id) or any int or long ID from your DB
这篇关于simplecursoradapter不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!