为什么我在SQLite列安卓中获取最后的数据



我想获取表格簿 ID 上的所有标题和theme_filepath = 表格主题的 book_id,但我得到了最后一个标题和主题file_path你能检查一下我的代码中的逻辑吗?

这是我的代码

public HashMap<String, ArrayList<String>> getBookTheme(){
    HashMap<String, ArrayList<String>> hm = new HashMap<String, ArrayList<String>>();
    ArrayList<String> list_book = new ArrayList<String>();
    ArrayList<String> list_theme = new ArrayList<String>();
    Cursor cursor = db.rawQuery("SELECT title, filepath FROM " + 
                BooksDBHelper.TABLE_BOOK + " INNER JOIN " + BooksDBHelper.TABLE_THEME +
                " ON " + BooksDBHelper.TABLE_BOOK + "." + BooksDBHelper.KEY_ID + " = " + 
                BooksDBHelper.TABLE_THEME + "." + BooksDBHelper.KEY_BOK_ID + 
                " WHERE " + BooksDBHelper.TABLE_BOOK + "." + BooksDBHelper.KEY_ID + " != ? ", new String[]{Integer.toString(0)});
    cursor.moveToLast();
    if(cursor.getCount() != 0){
        do{
            list_book.add(cursor.getString(cursor.getColumnIndex(BooksDBHelper.KEY_TITLE)));
            list_theme.add(cursor.getString(cursor.getColumnIndex(BooksDBHelper.KEY_fILEPATH)));

        }while(cursor.moveToNext());
        hm.put("title", list_book);
        hm.put("theme", list_theme);
    }
    return hm;
}

谢谢

因为cursor.moveToLast() .

考虑更换

cursor.moveToLast();
if(cursor.getCount() != 0){

if (cursor.moveToFirst()) {

最新更新