有没有人用过这个类,看看它在android 3.x和更高版本中是否被破坏了?它在以前的版本中对我来说工作得很好。下面是一个例子:
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);
}它没有显示任何东西,看起来像是在清理光标。对于SDK > 3.x,我是否遗漏了什么?
发布于 2012-01-06 02:20:11
好吧,我找到了一个解决方案:
我将CursorAdapter和SimpleCursorAdapter导入替换为兼容包上的导入,并使用CursorAdapter.swapCursor而不是CursorAdapter.changeCursor。
似乎与swapCursor没有关闭上一个光标有关。
https://stackoverflow.com/questions/8732187
复制相似问题