列表视图的 INNER JOIN 问题

INNER JOIN issue with list view

我有一个列表视图,当我在创建时调用 SQL 查询内部连接时,它没有执行任何操作,也没有发生错误

        public Cursor getBankBranch() {
    Cursor cursor;
    SQLiteDatabase db = mDbHelper.getReadableDatabase();
    String selectQuery = "SELECT  * FROM " + DataEntry.BRANCH_TABLE_NAME + " INNER JOIN  " 
            + DataEntry.BANK_TABLE_NAME + " ON " 
            + DataEntry.BANK_TABLE_NAME + "." + DataEntry.COLUMN_BANK_ID + "  = " 
            + DataEntry.BRANCH_TABLE_NAME + "." + DataEntry.COLUMN_BRANCH_BANK_ID;
    cursor = db.rawQuery(selectQuery, null);
    cursor.moveToFirst();
    cursor.close();
    return cursor;
}

这是table的内容

            String SQL_CREATE_BANK_TABLE = "CREATE TABLE " + DataEntry.BANK_TABLE_NAME + " ("
            + DataEntry.COLUMN_BANK_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + DataEntry.COLUMN_BANK_NAME + " TEXT );";

    String SQL_CREATE_BRANCH_TABLE = "CREATE TABLE " + DataEntry.BRANCH_TABLE_NAME + " ("
            + DataEntry.COLUMN_BRANCH_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + DataEntry.COLUMN_BRANCH_NAME + " TEXT , "
            + DataEntry.COLUMN_BRANCH_NUMBER + " TEXT , "
            + DataEntry.COLUMN_BRANCH_ADDRESS + " TEXT, "
            + DataEntry.COLUMN_BRANCH_BANK_ID + " INTEGER );";

    // Execute the SQL statement
    db.execSQL(SQL_CREATE_BANK_TABLE);
    db.execSQL(SQL_CREATE_BRANCH_TABLE);

你只是获取指向结果集的游标,然后将其移动到第一个结果,然后关闭它,但实际上并没有使用它。

让它工作的步骤

进行 select 查询

String selectQuery = "SELECT ..."

执行查询以获取游标

cursor = db.rawQuery(selectQuery, null);

创建一个游标适配器

MyCursorAdapter adapter = new MyCursorAdapter(this, cursor);

设置ListView的适配器

list.setAdapter(adapter);

here is an example of how to use it