我正在使用UNION從多個表執行搜索界面。搜索詞被過濾的類是SimpleCursorAdapter表單,我的問題是當我單擊搜索到的單詞時,我看到的唯一一個白色空白頁。從多個表中檢索數據 - Android Eclipse
這是我的代碼來檢索'更多信息'的話。我認爲問題出在WHERE條件。請幫幫我。謝謝。
commandId = getIntent().getIntExtra("COMMAND_ID", 0);
SQLiteDatabase db = (new DBHelper(this)).getWritableDatabase();
final String commandIdString = String.valueOf(commandId);
Cursor cursor = db.rawQuery("SELECT _id AS _id, name AS name, desc AS desc, syntax AS syntax, option AS option FROM comm_acc WHERE _id = ? " +
"UNION SELECT _id AS _id, name AS name, desc AS desc, syntax AS syntax, option AS option FROM comm_filems WHERE _id = ? " +
"UNION SELECT _id AS _id, name AS name, desc AS desc, syntax AS syntax, option AS option FROM comm_psu WHERE _id = ? " +
"UNION SELECT _id AS _id, name AS name, desc AS desc, syntax AS syntax, option AS option FROM comm_shells WHERE _id = ? " +
"UNION SELECT _id AS _id, name AS name, desc AS desc, syntax AS syntax, option AS option FROM comm_sic WHERE _id = ? " +
"UNION SELECT _id AS _id,name AS name, desc AS desc, syntax AS syntax, option AS option FROM comm_stp WHERE _id = ?",
new String[]{commandIdString, commandIdString, commandIdString, commandIdString, commandIdString, commandIdString});
if (cursor.getCount() == 1)
{
cursor.moveToFirst();
commandName = (TextView) findViewById (R.id.commandName);
commandName.setText(cursor.getString(cursor.getColumnIndex("name")));
commandDesc = (TextView) findViewById (R.id.commandDesc);
commandDesc.setText(cursor.getString(cursor.getColumnIndex("desc")));
commandSyntax = (TextView) findViewById (R.id.commandSyntax);
commandSyntax.setText(cursor.getString(cursor.getColumnIndex("syntax")));
commandOption = (TextView) findViewById (R.id.commandOption);
commandOption.setText(cursor.getString(cursor.getColumnIndex("option")));
}
}
您是否對數據庫使用了生成的SQL查詢? – Smutje 2014-12-04 14:54:04
它不會解決你的問題,但:「」+ commandId是凌亂的。爲什麼不使用:String.valueOf(commandId),而不是? – LokiSinclair 2014-12-04 14:54:13
我已經編輯了代碼,請再看一遍。它仍然是白色的空白頁面。 – user3398666 2014-12-04 16:16:30