Quantcast
Channel: After sorting JSONArray,Custom list view not changed? - Stack Overflow
Viewing all articles
Browse latest Browse all 6

Answer by Rujul Gandhi for After sorting JSONArray,Custom list view not changed?

$
0
0

Yes , i think you have to use model class. Here is example with onPostExecute.

    @Override    protected void onPostExecute(String s) {        super.onPostExecute(s);        pd.dismiss();        try {            JSONObject object = new JSONObject(s.toString());            YourModelNameList = new ArrayList<>();            if (object.getString("status").equalsIgnoreCase("true")) {                JSONArray array = object.getJSONArray("data");                for (int i = 0; i < array.length(); i++) {                    JSONObject jsonProduct = array.getJSONObject(i);                    YourModelName home = new Home();                    String special = jsonProduct.getString("special_price");                    home.setId(jsonProduct.getString("product_id"));                    home.setName(jsonProduct.getString("product_name"));                    home.setPrice(jsonProduct.getString("price"));                    YourModelArrayList.add(home);                }            }             Collections.sort(YourModelArrayList, new Comparator<YourModelName>() {                public int compare(YourModelName emp1, YourModelName emp2) {                    int price1 = emp1.getPrice();                    int price2 = emp2.getPrice();                    return Integer.compare(price1, price2);                }            });            adapter = new YourModelArrayListAdapter(getActivity(), YourModelArrayList);            recyclerView.setAdapter(adapter);        } catch (JSONException e) {            e.printStackTrace();        }    } 

Try this if this will help you. Thank you.


Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>