I have a ListView which onResume I am trying to populate with data from a SQL Lite Database. During resume I add a click listener and repopulate the List View. The onResume, populateListView(), and onPause methods are below. The full source code is available on GitHub.
onResume:
@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();
}
populateListView:
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);
}
}
I'm not doing anything special on the onPause, but since the values are stored in the database didn't think 开发者_如何学运维I would have to.
onPause
@Override
protected void onPause() {
unregisterReceiver(receiver);
super.onPause();
}
What am I doing wrong that is causing the ListView to not be refreshed onResume?
You could try moving setContentView(R.layout.main);
to your onCreate() method.
Setting it in onResume()
every time might cause issues.
精彩评论