我使用DialogFragment创建了一个自定义对话框,在对话框中,我可以将一些数据添加到SQLite数据库。此外,主活动中还有一个listview,它显示SQLite的数据。如何在使用DialogFragment更改数据后刷新ListView?
我想刷新列表视图,当我从对话框中添加数据到数据库。但是,我有一些问题。
我在onResume()中调用notifyDataSetChanged(),但是当我关闭对话框时,listview不刷新。如果我按主页按钮并从最近列表中打开活动,则列表视图将刷新。
@Override
protected void onResume() {
super.onResume();
listItem.clear();
ServerListDB db = new ServerListDB(context);
Cursor cursor = db.select();
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("serverName", String.valueOf(cursor.getString(1)));
map.put("serverIp", cursor.getString(2));
map.put("serverPort", cursor.getString(3));
listItem.add(map);
}
notifyDataSetChanged();
}
我添加log.v中的onPause(),并在对话框中显示,在onPause()没有被调用。 DialogFragment是否正确?
@Override
protected void onPause() {
super.onPause();
Log.v("Pause", "onPause() called!");
}
是的onResume甚至称,你检查了吗? – Dusan 2013-05-01 15:36:06
当对话框关闭时,onResume不会被调用,但如果我在最近的应用程序列表中选择活动,它将被调用 – rookiepeng 2013-05-01 16:37:15