Search code examples
androidlistviewnotifydatasetchanged

notifiyDataSetChanged() won't update adapter with new fields


I have a list of items: List<SomeObject> items that is mapped to an adapter to show on a ListView. When I set a new field for a specific item in that list and call adapter.notifyDataSetChanged() then list doesn't update. For example, I want to show a date TextView in a specific row in the ListView by setting

item.get(position).showDate(true);
adapter.notifyDataSetChanged();

The view doesn't show until I scroll away from that row and back to it (I'm assuming because of recycling).

Doing list.setAdapter(adapter); works but the entire view flashes and there shouldn't be a reason to re-set the adapter.

How can I get the list to update without scrolling?


Solution

  • You could try to change the List that is referenced in the adapter. Add something like this to your adapter:

     public void updateData(List<SomeObject> dataItems) {
            this.mDataItems = dataItems;            
            notifyDataSetChanged();
        }
    

    And then:

    items.get(position).showDate(true);
    adapter.updateData(items);