游标总是返回一行

时间:2014-05-21 12:49:56

标签: android sqlite android-cursor

我在桌子上有三排。但是在下面的代码中,即使选择了整个表,游标也始终只返回一行。我改变了条件和循环的几种方式,你可以看作评论。

public ArrayList <String> select1 (String ReservedState, String mycity, String mystreet, String mypostcode){
    SQLiteDatabase Database1=dbHelper1.getWritableDatabase();
    String[] columns={DbHelper1.KEY_ID1};
    //Cursor cursor = Database1.rawQuery("SELECT * FROM " + DbHelper1.TABLE_NAME_1, null);
    Cursor cursor=Database1.query(DbHelper1.TABLE_NAME_1,columns,null,null,null,null,null);
    //Cursor cursor=Database1.query(DbHelper1.TABLE_NAME_1,columns,"DbHelper1.KEY_RESERVEDSTATE like ?",new String[] {"+ReservedState+"},null,null,null);
    //Cursor cursor=Database1.query(DbHelper1.TABLE_NAME_1,columns,DbHelper1.KEY_RESERVEDSTATE + "=? ",new String[] {ReservedState},null,null,null);
    //StringBuffer buffer=new StringBuffer();
    Log.e("Cursor",""+cursor.getCount());
    ArrayList<String> al=new ArrayList<String>();
    cursor.moveToFirst();
    while(!cursor.isAfterLast()){
        int index1=cursor.getColumnIndex(DbHelper1.KEY_ID1);
        String id=cursor.getString(index1);
        al.add(id);
        cursor.moveToNext();
    }
    cursor.close();
    return al;
    /*if(!(cursor==null) && cursor.moveToFirst()){
        do{
            int index1=cursor.getColumnIndex(DbHelper1.KEY_ID1);
            String id=cursor.getString(index1);
            al.add(id);
        }while(cursor.moveToNext());
    }
    cursor.close();
    return al;*/
/*while(cursor.moveToNext()){
    int index1=cursor.getColumnIndex(DbHelper1.KEY_ID1);
    //int index2=cursor.getColumnIndex(DbHelper1.KEY_RESERVEDSTATE);  
    //int index3=cursor.getColumnIndex(DbHelper1.KEY_GEOGRAPHICALLOCATION);
    //int index4=cursor.getColumnIndex(DbHelper1.KEY_CITY);
    //int index5=cursor.getColumnIndex(DbHelper1.KEY_POSTCODE);
    //int index6=cursor.getColumnIndex(DbHelper1.KEY_STREET);
    String id=cursor.getString(index1);
    buffer.append(id);
}
return buffer.toString();*/
}

0 个答案:

没有答案