我使用光标填充ListView,但当我离开活动并返回时,ListView是空的。这是我的代码:
@Override
public void onCreate(Bundle savedInstanceState) {
...
DBAdapter db = new DBAdapter(context);
db.open();
Cursor c = db.getAll();
db.close();
startManagingCursor(c);
String[] columns = new String[] { ... };
int[] to = new int[] { ... };
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.list_item, c, columns, to);
this.setListAdapter(mAdapter);
...
}
我在这里看到过关于保存光标位置的问题,但没有看到光标本身。可能是我遗漏了什么,我应该保存光标吗(我该怎么做?)或者每次使用我的数据库适配器创建新的光标更好(更快、更便宜)?
谢谢