2

Hello Iam newbie in android so dont judge too strong.I develop app where I have listview where i get json data and parse it using volley and stored in ArrayList so I wondered is there best and fastest way to update listivew now I have:

      List.clear();

    //volley request
    ...
   adapter.notifyDataSetChanged();`

But its take a lot of time to updating if there are many data does anybody know how update like facebook etc.I am tried to use only make volley request and adapter.notifyDataSetChanged() but it gives me doubles data if update three times it gives copies data again how to solve this?I hesr about Set but i should have ordered list.NOTE:when making json request some data in server may deleted and also its must to deleted in listview in app Please HELP

             JsonObjectRequest jsonReq = new JsonObjectRequest(Method.GET,
                URL_FEED, null, new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject response) {
                        VolleyLog.d(TAG, "Response: " + response.toString());
                        if (response != null) {
                            parseJsonFeed(response);
                        }
                    }
                }, new Response.ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        VolleyLog.d(TAG, "Error: " + error.getMessage());
                    }
                });



    void parseJsonFeed(JSONObject response) {
    try {
        JSONArray feedArray = response.getJSONArray("feed");

        for (int i = 0; i < feedArray.length(); i++) {
            JSONObject feedObj = (JSONObject) feedArray.get(i);
          //addin response to views

        }

        // notify data changes to list adapater
        listAdapter.notifyDataSetChanged();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Jessie
  • 105
  • 1
  • 10
  • First I do not think changing your internet library makes a lot difference to your situation, second you should think about how you parse json, for example use other libraries like Jackson or Gson, third you should post how you add the data to your list. – mmlooloo Jan 11 '15 at 08:40

1 Answers1

1

Make Json Volley request then check with boolean if you have this data if yes you should continue else you should add to listview,use adapter.notifyDataSetChanged(); this link may help you notifyDataSetChanged example

Community
  • 1
  • 1
Sasha
  • 644
  • 8
  • 22