Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 是否可以从光标行id填充列表视图?_Android - Fatal编程技术网

Android 是否可以从光标行id填充列表视图?

Android 是否可以从光标行id填充列表视图?,android,Android,是否可以基于自定义游标适配器中的行Id填充listview。我不断收到一个错误“illegalArguementException列:\u id不存在”。但是数据库已经有了它,并且已经被正确地使用了。我不知道该怎么办,因为我需要从同一个数据库中填充不同的ListView,而且我不想创建多个仍然具有相同列名的数据库。任何想法都将不胜感激。谢谢 以下是数据库代码正在冻结: public Cursor retrieveItemRow(long Id){ open(); String[]

是否可以基于自定义游标适配器中的行Id填充listview。我不断收到一个错误“illegalArguementException列:\u id不存在”。但是数据库已经有了它,并且已经被正确地使用了。我不知道该怎么办,因为我需要从同一个数据库中填充不同的ListView,而且我不想创建多个仍然具有相同列名的数据库。任何想法都将不胜感激。谢谢

以下是数据库代码正在冻结:

public Cursor retrieveItemRow(long Id){
        open();
String[] Columns = new String[] {TITLE,DATE, TIME};
Cursor row = db.query(true,DATABASE_TABLE, Columns, KEY_ID +"=" +Id, null, null, null, null,null);
    if(row != null){
    row.moveToNext();
    return row;
    }
    return row;
      }
下面是我正在尝试调用的方法:

 public void fillRowData(long Id) {

Cursor cursor = adapter.retrieveRow(id);
startManagingCursor(cursor);
String[] from = new String[]{DBAdapter.TITLE, DBAdapter.DATE, DBAdapter.TIME};
int[] to = new int[]{R.id.Name, R.id.Date, R.id.Time};

customCursor items = new customCursor(this, R.layout.viewlist, cursor, from, to);
setListAdapter(items);          

}

确保在传递到适配器的游标所表示的SELECT语句中包含_id。例如,如果我使用的是
SimpleCursorAdapter(上下文上下文、int布局、光标c、字符串[]from、int[]to)
,我的
光标c
将以类似“SELECT\u id、name from users;”的形式出现

从:

本教程在数据库帮助器类中定义了一个方法,该方法返回所有
Note
对象。实际上,他们使用的是
SQLiteDatabase
query
方法,该方法返回
游标
对象。查询的select字符串是您应该包含_id列的位置

因此,在您的示例中,需要将
KEY\u ID
添加到
Columns
字符串数组变量中,因为这些列包含在select语句(db.query())中。文件中也提到了这一点:

光标必须包含名为的列 “\u id”或该类将不起作用


抱歉打扰了,我有点困惑。我是在调用游标的数据库类中还是在适配器中包含select语句。请链接到这方面的任何示例都将不胜感激。我刚刚更新了我的初始响应,请查看并让我知道这是否有意义。我已经有了一个从listview填充的listview。我现在要做的是用我已经获得的rowId填充另一个listview。类似于游标c=mdbHelper.fetchNote(rowId)。这就是我得到错误的地方。您使用的select语句是什么?发布所有对调试情况有用的代码。我在代码中不使用任何select语句。我添加了导致问题的数据库代码。
private void fillData() {
     // Get all of the notes from the database and create the item list
     Cursor c = mDbHelper.fetchAllNotes();
     startManagingCursor(c);

     String[] from = new String[] { NotesDbAdapter.KEY_TITLE };
     int[] to = new int[] { R.id.text1 };

     // Now create an array adapter and set it to display using our row
     SimpleCursorAdapter notes =
          new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
     setListAdapter(notes);
}