notifyDataSetChanged not working

后端 未结 2 1576
南方客
南方客 2020-12-18 03:20

My app uses a MultiColumnListView (https://github.com/huewu/PinterestLikeAdapterView) and as its name says it helps creating multi column list views.

T

相关标签:
2条回答
  • 2020-12-18 03:26

    You need to clear older myList.clear() and then call adapter.notifyDataSetChanged()

    Update:

    Change your code like:

    public MiAdaptadorListaComercios(Context c,List<Comercio> myList){
    this.contexto = c;
    this.myList = new ArrayList<Comercio>();
    }
    

    Also, do it like

    myList.clear();
    myList.addAll(originalList);   
    
    0 讨论(0)
  • 2020-12-18 03:34

    just change your myList and call adapter.notifyDataSetChanged() don't set a new adapter each time.

    In the constructor of your custom adapter do call super that takes ArrayList as the argument.

    call this:

    public MiAdaptadorListaComercios(Context c,List<Comercio> myList){
        super(c,0,myList);
        this.contexto = c;
        this.myList = myList;
    }
    

    You can keep the adapter as it is the problem is in this line:

    myList = filteredList;
    

    instead of changing the reference you should change the list itself.

    myList.clear();
    myList.addAll(filteredList);
    

    By doing this you will loose your original list to I would suggest keeping another list call ed originalList which will have the complete list and initialize myList in onCreate by:

    myList=new ArrayList(originalList);
    

    so every time you want to re-set just call:

    myList.clear();
    myList.addAll(originalList);    
    

    and in

        for(Comercio co : originalList)
                {
                    if(co.getName().contains(filer))
                    {
                        filteredList.add(co);
                    }
                }
    
    0 讨论(0)
提交回复
热议问题