我希望获得表主题的id = table_id的所有标题和theme_filepath,但我得到一个最后的标题和主题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;
}
谢谢
答案 0 :(得分:1)
由于cursor.moveToLast()
。
考虑更换
cursor.moveToLast();
if(cursor.getCount() != 0){
与
if (cursor.moveToFirst()) {