开发者

Notify ListView on receiving Dataset

开发者 https://www.devze.com 2023-03-22 20:18 出处:网络
I have a ListView that gets its dataset from a BaseAdapter. The ListView receives data when a menuItem is clicked.

I have a ListView that gets its dataset from a BaseAdapter. The ListView receives data when a menuItem is clicked. I am not able to notify my listView or my ListAdapter (inboxAdapter.notifyDataSetChanged()), doesnt work. Any other approaches.

case R.id.Get:
  retrieveList();
  inboxEmails = EmailElement.parseContent();
  inboxAdapter = new nboxAdapter(getApplicationContext(),inboxEmails);
   if(inboxAdapter !=null){
    listView.setAdapter(inboxAdapter);
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    inboxAdapter.no开发者_开发技巧tifyDataSetChanged();
  }
break;

//this method retrieveList by sending sms

private void retrieveList(){
  registerReceiver(new SMSSentReciever(), new IntentFilter(SMSInfo.SENT));
  registerReceiver(new SMSDeliveredReciever(), new IntentFilter(SMSInfo.DELIVERED));
  PendingIntent sentIntent = PendingIntent.getBroadcast(this, 0, new Intent(SMSInfo.SENT), 0);
  PendingIntent deliveryIntent = PendingIntent.getBroadcast(this, 0, new Intent(SMSInfo.DELIVERED),0);
  SmsManager.getDefault().sendTextMessage("5556",null, "fruits", sentIntent, deliveryIntent);

}

Based on the message from broadcast i need to update or notify my Listview, for now when i click the menu firstly i get my message on the emulator and then from the other emulator i send above message, the toast is shown,but not the listview but once i click the menu again i finally get the listview. WHat have i done wrong?


Instead of calling notifyDataSetChanged(), calling listView1.setAdapter(adapter) will force the listview to refresh.

0

精彩评论

暂无评论...
验证码 换一张
取 消