【发布时间】:2019-01-22 02:34:34
【问题描述】:
我收到了来自 JSON i 的响应,我收到了两个以上的 jSONArray。像这样我拍摄了 logcat 数据的快照here is logcat data which I am fetching jsonarrays from my response
现在的问题是如何将所有这些 arraylist 填充到单个 arraylist 中以及如何在 recyclerView 中显示。这是我的响应代码
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject(response);
JSONArray hotDealProduct = jsonObject.getJSONArray("ListProduct");
setHotDealAdapter(hotDealProduct);
Log.e(TAG,hotDealProduct.toString());
} catch (JSONException e) {
e.printStackTrace();
}
这是我的 setHotDealAdapter() 代码:
for (int i=0;i<hotDealProduct.length();i++) {
try {
JSONObject object = hotDealProduct.getJSONObject(i);
final String discount = object.getString("discount");
final String price = object.getString("Price");
final String salePrice = object.getString("SalePrice");
final String image = object.getString("MainImage");
final String name = object.getString("Name");
products.add(new HotDeal(1,discount, price ,image,salePrice,name));
adapter = new HotDealAdapter(context,products);
rvHotDeal.setLayoutManager(new GridLayoutManager(context,2));
rvHotDeal.setAdapter(adapter);
adapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
【问题讨论】:
-
什么问题我看到你已经解决了
-
问题是我如何将所有 jsonarrayList 附加到单个数组列表
-
我会更好地发布答案
标签: android android-fragments android-recyclerview android-volley