1

我的应用程序中有 FB、Google 和正常登录。当我使用 FB 或 google 登录时,一切都很好,但是每当我从应用程序注册并立即登录时,我没有在 CartActivity RecyclerView 中获取数据,但数据显示在邮递员中或浏览器。当我卸载应用程序并重新安装数据时,再次开始显示旧的登录凭据。购物车活动:

    try {
        StringRequest stringRequest = new StringRequest(Request.Method.GET, url2,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        pd.dismiss();
                        // Toast.makeText(CartActivity.this, "responce"+response.toString(), Toast.LENGTH_SHORT).show();
                        System.out.println("Response is : " + response);
                        try {
                            JSONObject jsono = new JSONObject(response);
                            if (jsono.getString("status").equals("success")) {
                                JSONArray jarray = jsono.getJSONArray("data");
                                for (int i = 0; i < jarray.length(); i++) {
                                    JSONObject object = jarray.getJSONObject(i);
                                    String total = object.getString("cart_total");

                                    jarray = jsono.getJSONArray("data");
                                    JSONArray jarray1 = object.getJSONArray("product_description");
                                    for (int j = 0; j < jarray1.length(); j++) {
                                        JSONObject object1 = jarray1.getJSONObject(j);

                                        JSONArray jarray2 = object1.getJSONArray("data");
                                        for (int k = 0; k < jarray2.length(); k++) {
                                            JSONObject object2 = jarray2.getJSONObject(k);
                                            String Name = object2.getString("product_name");
                                            String Image = object2.getString("product_image");
                                            String Price = object2.getString("product_price");
                                            String Qty = object2.getString("product_qty");
                                            String sku = object2.getString("product_sku");
                                            String ProId = object2.getString("product_id");
                                          System.out.println("VALUES: " + Name + "price" + Price + "qty" + Qty + sku + "proid" + ProId);
                                        }
                                    }
                                }
                                rccart.setAdapter(cartAdapter);
                                cartAdapter.notifyDataSetChanged();
                            } else {
                                Toast.makeText(getApplicationContext(), "Something went wrong...", Toast.LENGTH_SHORT).show();
                            }
                        } catch (Exception ex) {
                            System.out.println("EXCPTION IN SUCCESS REQUEST : " + ex.toString());
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        pd.dismiss();
                        System.out.println("ERROR IN REQUEST : " + error.getMessage());
                    }

                })
        {
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<String, String>();
                return params;
            }
        };
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(
                90000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        RequestQueue requestQueue = Volley.newRequestQueue(CartActivity.this);
        requestQueue.add(stringRequest);
        pd = new ProgressDialog(CartActivity.this);
        pd.setMessage("Loading...");
        pd.show();
    } catch (Exception ex) {
    }


}
4

2 回答 2

0

如果您获得如下代码的响应时间,请创建一个定义所有字段的 pojo 类。

public class DataClass {
String Name ;
String Image ;
String Price ;
String Qty ;
String sku ;
String ProId;

public String getName() {
    return Name;
}

public void setName(String name) {
    Name = name;
}

public String getImage() {
    return Image;
}

public void setImage(String image) {
    Image = image;
}

public String getPrice() {
    return Price;
}

public void setPrice(String price) {
    Price = price;
}

public String getQty() {
    return Qty;
}

public void setQty(String qty) {
    Qty = qty;
}

public String getSku() {
    return sku;
}

public void setSku(String sku) {
    this.sku = sku;
}

public String getProId() {
    return ProId;
}

public void setProId(String proId) {
    ProId = proId;
}

}

在回收器视图适配器中添加列表,如 ....

 private List<DataClass> mDataList=new ArrayList<>();

public CustomAdapter(List<DataClass> mDataList) {
    this.mDataList = mDataList;
}

然后在获取响应数据后添加到数组列表并传递到适配器..

private List<DataClass> mListData=new ArrayList<>();// define in type-array in your pojo class name
  for (int k = 0; k < jarray2.length(); k++) {
        JSONObject object2 = jarray2.getJSONObject(k);
        DataClass dataClass=new DataClass();
        String Name = object2.getString("product_name");
        String Image = object2.getString("product_image");
        String Price = object2.getString("product_price");
        String Qty = object2.getString("product_qty");
        String sku = object2.getString("product_sku");
        String ProId = object2.getString("product_id");
        dataClass.setName(Name);
        dataClass.setImage(Image);
        dataClass.setPrice(Price);
        dataClass.setQty(Qty);
        dataClass.setSku(sku);
        dataClass.setProId(ProId);
        mListData.add(dataClass);
        System.out.println("VALUES: " + Name + "price" + Price + "qty" + Qty + sku + "proid" + ProId);
    }
    if (!mListData.isEmpty()){
        cartAdapter=new CartAdapter(mListData);
        rccart.setAdapter(cartAdapter);
        cartAdapter.notifyDataSetChanged();
    }
于 2018-02-26T07:00:46.237 回答
0

得到了解决方案。这是因为缓存而发生的。刚刚清除缓存并解决问题。

于 2018-02-26T12:36:00.273 回答