Has anyone used this class and see if it is broken in android version 3.x and above? It worked fine for me in previous versions. Here’s an example:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MatrixCursor cursorOne = new MatrixCursor(new String[]{ "_id", "name", "description" });
cursorOne.addRow(new Object[]{ 5, "Object 2", "Description 2" });
cursorOne.addRow(new Object[]{ 5, "Object 3", "Description 3" });
cursorOne.addRow(new Object[]{ 5, "Object 4", "Description 4" });
cursorOne.addRow(new Object[]{ 5, "Object 5", "Description 5" });
CursorAdapter cursorAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cursorOne, new String[] { "name", "description" }, new int []{ android.R.id.text1, android.R.id.text2 });
MatrixCursor cursorTwo = new MatrixCursor(new String[]{ "_id", "name", "description" });
cursorTwo.addRow(new Object[]{ 5, "Object 2", "Description 2" });
cursorTwo.addRow(new Object[]{ 5, "Object 3", "Description 3" });
cursorTwo.addRow(new Object[]{ 5, "Object 4", "Description 4" });
cursorTwo.addRow(new Object[]{ 5, "Object 5", "Description 5" });
MergeCursor mergeCursor = new MergeCursor(new Cursor[] { cursorOne, cursorTwo });
cursorAdapter.changeCursor(mergeCursor);
setListAdapter(cursorAdapter);
}
It doesn’t show anything, it seems like it’s cleaning the cursors. Am I missing something for the SDK > 3.x?
Okay, I found a solution:
I replaced the
CursorAdapterandSimpleCursorAdapterimports for the ones on the compatibility package and usedCursorAdapter.swapCursorinstead ofCursorAdapter.changeCursor.Seems to be something related that
swapCursordoes not close the previous cursor.