After sorting JSONArray,Custom list view not changed?

前端 未结 5 1973
你的背包
你的背包 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:44

    In my case i got homeList(ArrayList of model 'Home') from JSONParser class so befor setAdapter

     Collections.sort(homeList, new Comparator() {
                        public int compare(Home emp1, Home emp2) {
                            int price1 = emp1.getPrice();
                            int price2 = emp2.getPrice();
    
    
    
                            return Integer.compare(price1, price2);
    
                        }
                    });
        Adapter adapter = new Adapter(getActivity(),homeList);
        listView.setadapter(adapter);
    

    So this will first sort whole arraylist and then we need to setAdapter.

    Try this i think this will help you.

提交回复
热议问题