我有一个onCreate()
使用datasource.open()
and的方法datasource.close()
。如果datasource.close();
在末尾发出问题onCreate()
,我的 ListView SimpleCursorAdapter 始终为空白。
如果我datasource.close();
从 ListView 的末尾删除,onCreate()
则会填充。
我一生都无法弄清楚为什么会这样。
任何人都有任何文件说明为什么会发生这种情况?
示例代码:
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
Bundle extras = getIntent().getExtras();
id = extras.getLong("extraID");
setContentView(R.layout.main);
datasource = new SMSDataSource(this);
datasource.open();
Cursor groupCursor = datasource.queryByGroup(long id);
contactAdapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2, // Use a template
// that displays a
// text view
getCur, // Give the cursor to the list adapter
new String[] { DBManagement.CONTACTS_COLUMN_NAME,
DBManagement.CONTACTS_COLUMN_NUMBER }, // Map the NAME
// column in the
// people database to...
layouts); // The "text1" view defined in
// the XML template
list = (ListView) findViewById(android.R.id.list);
list.setAdapter(contactAdapter);
registerForContextMenu(list);
groupCursor.close();
datasource.close();
}