After sorting JSONArray,Custom list view not changed?

前端 未结 5 1974
你的背包
你的背包 2020-12-07 05:58

I am sorting JSONArray and show them in a custom list view, but after sorting the data does not changed in custom list view.

Here is my code for fab button to select

5条回答
  •  醉话见心
    2020-12-07 06:40

    Before set the data to Listview, you should sort the data using comparator class in java.

    you create one Model class with all variable what you want (name,booth_id etc)and store the each object into the ArrayList.

    Collections.sort(ArrayListObject,new NameComparator()); 
    

    example

    class NameComparator implements Comparator{  
    public int compare(Object o1,Object o2){  
    YourClassName s1=(YourClassName )o1;  
    YourClassName s2=(YourClassName )o2;  
    
    return s1.name.compareTo(s2.name);  
    }  
    } 
    

提交回复
热议问题