Skip to content Skip to sidebar Skip to footer

Cannot Use Notifydatasetchanged To Update Adapter

I cannot update my ListView after deleting an item. Listview item gets deleted from database but I cannot update my adapter and it keeps showing deleted item in listView. if I put

Solution 1:

Solution 1 (Preferred)

notifyDataSetChanged is not available for SimpleAdapter. SimpleAdapter is meant for static data. You should use a different type of adapter, like ArrayAdapter. More information is here

Solution 2

Call this method instead of adapter.notifyDataSetChanged();

publicvoidrefreshList(){
    List<TRListFormat> list = trDb.getAllReminders();
    items = newArrayList<>();
    for (TRListFormat val : list) {
        HashMap<String, String> map = newHashMap<>();
        map.put("title",val.getTitle());
        map.put("description", val.getDes());
        map.put("date", val.getDate());
        map.put("time", val.getTime());

        items.add(map);
    }

    adapter = newSimpleAdapter(this, items, R.layout.tr_list_format,
      newString[] { "title", "description", "date", "time" },
      new int[] {R.id.tbr_title, R.id.tbr_des, R.id.tbr_date, R.id.tbr_time     });

    lv.setAdapter(adapter);
}

Post a Comment for "Cannot Use Notifydatasetchanged To Update Adapter"