使用 JSON Parsing with volley 更新列表视图的最佳方法

Best way to update listview using JSON Parsing with volley

你好,我是 android 的新手,所以不要过多判断 strong.I 开发应用程序,我有列表视图,我在其中获取 json 数据并使用 volley 解析它并存储在 ArrayList 中,所以我想知道有没有最好和最快的方法来更新 listivew 现在我有:

      List.clear();

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

但是如果有很多数据,更新会花费很多时间有谁知道像 facebook etc.I 这样的更新是如何尝试只使用 make volley request 和 adapter.notifyDataSetChanged() 但它给出了如果更新三次我会加倍数据它再次提供副本数据如何解决这个问题?我对 Set 但我应该订购 list.NOTE: 当 json 请求服务器中的一些数据可能被删除并且它必须被删除要在应用程序的列表视图中删除请帮助

             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();
    }
}

发出 Json Volley 请求,然后用布尔值检查你是否有此数据,如果是,你应该继续,否则你应该添加到列表视图,使用 adapter.notifyDataSetChanged(); 这个 link 可能对你有帮助 notifyDataSetChanged example