【发布时间】:2018-10-29 23:22:53
【问题描述】:
我正在尝试从我的数据库中搜索一个主要包含 3 列(问题、答案和 cmets)的字符串,因此用户可以搜索一个单词,并且该单词在任何列中的任何实例都应该出现在搜索中结果。 我使用了这段代码,但它只返回第一列的搜索。你知道我的代码有什么问题吗:
public Cursor search(String searchString) {
String[] columns = new String[]{ KEY_QUESTION,KEY_ANSWER, KEY_COMMENT};
String where = KEY_QUESTION + " LIKE ? OR "+ KEY_ANSWER + " LIKE ? ";
searchString = "%" + searchString + "%";
String[] whereArgs = new String[]{searchString};
Cursor cursor = null;
try {if (database == null) {
database = openHelper.getReadableDatabase();
}
cursor = database.query(TABLE_FLASH, columns, where, whereArgs, null, null, null);
} catch (Exception e) {
Log.d(TAG, "SEARCH EXCEPTION! " + e); // Just log the exception
}
return cursor;
}
【问题讨论】:
标签: java android sqlite cursor android-sqlite