我有一个 ListView,我正在尝试使用 SQL Lite 数据库中的数据填充它的 onResume。在恢复期间,我添加了一个单击侦听器并重新填充列表视图。下面是 onResume、populateListView() 和 onPause 方法。完整的源代码可在 GitHub 上获得。
简历:
@Override
protected void onResume() {
IntentFilter filter = new IntentFilter();
filter.addAction(TalkServerIntent.INTENT_NEW_MESSAGES.toString());
registerReceiver(receiver, filter);
setContentView(R.layout.main);
talkListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parentView, View childView,
int position, long id) {
GeoCamTalkMessage msg = adapter.getTalkMessage(position);
if (msg.hasAudio()) {
try {
UIUtils.playAudio(getApplicationContext(), msg, player,
siteAuth);
} catch (Exception e) {
UIUtils.displayException(getApplicationContext(), e,
"Cannot retrieve audio");
}
}
}
});
populateListView();
super.onResume();
}
填充列表视图:
private void populateListView() {
try {
talkMessages = messageStore.getAllMessages();
} catch (Exception e) {
Log.i("Talk", "Error:" + e.getMessage());
}
if (talkMessages != null) {
adapter.setTalkMessages(talkMessages);
talkListView.setAdapter(adapter);
}
}
我没有在 onPause 上做任何特别的事情,但由于值存储在数据库中,我认为我不必这样做。
暂停
@Override
protected void onPause() {
unregisterReceiver(receiver);
super.onPause();
}
我做错了什么导致 ListView 无法在 onResume 上刷新?