BaseAdapter notifyDatasetChanged() called but getView() is never called

前端 未结 4 1136
梦毁少年i
梦毁少年i 2021-01-01 21:58

I have a custom adapter that visualize each row in the list of Orders.

public class OrderRowAdapter extends BaseAdapter implements OnClickListener {
    Ord         


        
4条回答
  •  执笔经年
    2021-01-01 22:46

    To change the content of your ListView, you must keep using the same reference to the List. Here you're creating another list and assigning it to the items_ variable (which does not contain the list itself, it's just a place to store a reference to a List), but your View still has a reference to the old list.

    Instead of items_ = new_order_list this should work :

    items_.clear();
    items_.addAll(new_order_list);
    

    EDIT :

    To explain it better, try to create a new variable named old_items :

    public void setNewOrderList(List new_order_list)
    {
        Log.d(TAG, "New Order List available. Num items = " + new_order_list.size());
    
        List old_items = items_; // store the reference to the old list
        items_ = new_order_list;
    
        Log.d(TAG, "items_.size() = " + items_.size());
        Log.d(TAG, "old_items.size() = " + old_items.size()); // The old list still exists, and it's the one used by your ListView
    
        notifyDataSetChanged();
    }
    

提交回复
热议问题