Android 为什么我在sqlite列中得到最后一个数据
我想获得表book=book\u id上的所有标题和主题文件路径,但我得到了最后一个标题和主题文件路径。请检查我代码中的逻辑 这是我的密码Android 为什么我在sqlite列中得到最后一个数据,android,logic,android-sqlite,inner-join,Android,Logic,Android Sqlite,Inner Join,我想获得表book=book\u id上的所有标题和主题文件路径,但我得到了最后一个标题和主题文件路径。请检查我代码中的逻辑 这是我的密码 public HashMap<String, ArrayList<String>> getBookTheme(){ HashMap<String, ArrayList<String>> hm = new HashMap<String, ArrayList<String>>();
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;
}
public HashMap getBookTheme(){
HashMap hm=新的HashMap();
ArrayList_book=新建ArrayList();
ArrayList_theme=新建ArrayList();
Cursor Cursor=db.rawQuery(“从”+
BooksDBHelper.TABLE_BOOK+“内部连接”+BooksDBHelper.TABLE_主题+
“在”+BooksDBHelper.TABLE_BOOK+“+BooksDBHelper.KEY_ID+”=“+
BooksDBHelper.TABLE_主题+““+BooksDBHelper.KEY_BOK_ID+
其中“+BooksDBHelper.TABLE_BOOK+”“+BooksDBHelper.KEY_ID+”!=?”,新字符串[]{Integer.toString(0)});
cursor.moveToLast();
if(cursor.getCount()!=0){
做{
list_book.add(cursor.getString(cursor.getColumnIndex(BooksDBHelper.KEY_TITLE));
list_theme.add(cursor.getString(cursor.getColumnIndex(BooksDBHelper.KEY_文件路径));
}while(cursor.moveToNext());
hm.put(“标题”,列表和书籍);
hm.put(“主题”,列表主题);
}
返回hm;
}
感谢您,因为
cursor.moveToLast()
考虑更换
cursor.moveToLast();
if(cursor.getCount() != 0){
与
if (cursor.moveToFirst()) {