我想为搜索小部件添加一些建议,但我不知道如何显示最近和自定义的建议。下面的片段给了我一个
CursorIndexOutOfBoundsException:Requested column:4,#of columns:4
有什么想法吗?
我的自定义建议代码
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
List<String> suggestions = new ArrayList<String>();
suggestions.add("iphone");
Cursor recentCursor = super.query(uri, projection, selection, selectionArgs,
sortOrder);
MatrixCursor cursor = new MatrixCursor(new String[] { BaseColumns._ID,
SearchManager.SUGGEST_COLUMN_TEXT_1,
SearchManager.SUGGEST_COLUMN_INTENT_DATA,
SearchManager.SUGGEST_COLUMN_QUERY } );
for (int i = 0; i < suggestions.size(); ++i) {
String suggestion = suggestions.get(i);
Object[] row = { Integer.toString(i),
suggestion,
suggestion, suggestion };
cursor.addRow(row);
}
Cursor[] cursors = new Cursor[] { recentCursor, cursor};
return new MergeCursor(cursors);
}
答案 0 :(得分:0)
recentCursor有第5列是SUGGEST_COLUMN_FORMAT,所以你不能将5列合并到4
答案 1 :(得分:0)
我相信您忘记了将SUGGEST_COLUMN_ICON_1
列添加到光标。