问题出在 onpostexecute 方法中
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
contactListView = getListView();
contactListView.setOnItemClickListener(viewContactListener);
String[] from = new String[]{"name"};
int[] to = new int[]{R.id.contactTextView};
@SuppressWarnings("deprecation")
CursorAdapter contactAdapter = new SimpleCursorAdapter(AddressBook.this,
R.layout.contact_list_item, null, from, to);
setListAdapter(contactAdapter);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
new GetContactsTask().execute((Object[])null);
}
@SuppressWarnings("deprecation")
@Override
protected void onStop() {
// TODO Auto-generated method stub
Cursor cursor = contactAdapter.getCursor();
if(cursor != null)
cursor.deactivate();
contactAdapter.changeCursor(null);
super.onStop();
}
private class GetContactsTask extends AsyncTask<Object, Object, Cursor>{
DatabaseConnector databaseConnector = DatabaseConnector(AddressBook.this);
@Override
protected Cursor doInBackground(Object... params) {
// TODO Auto-generated method stub
databaseConnector.open();
return databaseConnector.getAllContacts();
}
@Override
protected void onPostExecute(Cursor result) {
contactAdapter.changeCursor(result);
databaseConnector.close();
}
}