从 Y 列获取所有字符串 X 并作为游标返回的算法是什么?我需要一个多次返回光标的函数,所以算法必须考虑到这一点。
我会很感激的。
更新:
public Comment search1(){
List<Comment> comments = new ArrayList<Comment>();
Cursor cursor = database.query(MySQLiteHelper.TABLE_COMMENTS,
allColumns, MySQLiteHelper.COLUMN_NAME +" LIKE" + "'%QUERY%'", null, null, null, null);
cursor.moveToFirst();
Comment newComment = new Comment();
//set values of this comment
newComment = cursorToComment(cursor);
//Close cursor
cursor.close();
return newComment;
}
忽略 Comment 部分,这是我用于 ListView 适配器的部分。
更新 2:
这有效:
public List<Comment> search2() {
List<Comment> comments = new ArrayList<Comment>();
Cursor cursor = database.query(MySQLiteHelper.TABLE_COMMENTS,
allColumns, MySQLiteHelper.COLUMN_NAME +" LIKE" + "'%QUERY%'", null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Comment comment = cursorToComment(cursor);
comments.add(comment);
cursor.moveToNext();
}
// Make sure to close the cursor
cursor.close();
return comments;
}