Guest User

Untitled

a guest
Aug 15th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. JSONObject jsonObject = null;
  2. try {
  3. jsonObject = new JSONObject(response);
  4. JSONArray hotDealProduct = jsonObject.getJSONArray("ListProduct");
  5. setHotDealAdapter(hotDealProduct);
  6. Log.e(TAG,hotDealProduct.toString());
  7. } catch (JSONException e) {
  8. e.printStackTrace();
  9. }
  10.  
  11. for (int i=0;i<hotDealProduct.length();i++) {
  12. try {
  13. JSONObject object = hotDealProduct.getJSONObject(i);
  14. final String discount = object.getString("discount");
  15. final String price = object.getString("Price");
  16. final String salePrice = object.getString("SalePrice");
  17. final String image = object.getString("MainImage");
  18. final String name = object.getString("Name");
  19. products.add(new HotDeal(1,discount, price ,image,salePrice,name));
  20. adapter = new HotDealAdapter(context,products);
  21. rvHotDeal.setLayoutManager(new GridLayoutManager(context,2));
  22. rvHotDeal.setAdapter(adapter);
  23. adapter.notifyDataSetChanged();
  24. } catch (JSONException e) {
  25. e.printStackTrace();
  26. }
  27.  
  28. for (int i=0;i<hotDealProduct.length();i++) {
  29. try {
  30. JSONObject object = hotDealProduct.getJSONObject(i);
  31. final String discount = object.getString("discount");
  32. final String price = object.getString("Price");
  33. final String salePrice = object.getString("SalePrice");
  34. final String image = object.getString("MainImage");
  35. final String name = object.getString("Name");
  36. products.add(new HotDeal(1,discount, price ,image,salePrice,name));
  37.  
  38. } catch (JSONException e) {
  39. e.printStackTrace();
  40. }
  41. adapter = new HotDealAdapter(context,products);
  42. rvHotDeal.setLayoutManager(new GridLayoutManager(context,2));
  43. rvHotDeal.setAdapter(adapter);
  44. adapter.notifyDataSetChanged();
  45.  
  46. for (int i=0;i<hotDealProduct.length();i++) {
  47. try {
  48. JSONObject object = hotDealProduct.getJSONObject(i);
  49. final String discount = object.getString("discount");
  50. final String price = object.getString("Price");
  51. final String salePrice = object.getString("SalePrice");
  52. final String image = object.getString("MainImage");
  53. final String name = object.getString("Name");
  54. products.add(new HotDeal(1,discount, price ,image,salePrice,name));
  55.  
  56. } catch (JSONException e) {
  57. e.printStackTrace();
  58. }
  59. }
  60.  
  61. adapter = new HotDealAdapter(context,products);
  62. rvHotDeal.setLayoutManager(new GridLayoutManager(context,2));
  63. rvHotDeal.setAdapter(adapter);
  64.  
  65. implementation 'com.google.code.gson:gson:2.8.2'
  66.  
  67. ArrayList<YourPOJO> itemlist = new ArrayList<>();
  68.  
  69. {
  70. // Your code implementation of binding data to recyclerview :
  71.  
  72. GsonBuilder gsonbuilder= new GsonBuilder();
  73.  
  74. Gson gson=gsonbuilder.create();
  75. //response = its your json string from server
  76. itemList =gson.fromJson(response, new TypeToken<List<YourPOJO>>(){}.getType());
  77.  
  78. yourAdapter = new YourAdapter(itemList);
  79.  
  80. yourRecyclerview.setAdapter(yourAdapter);
  81.  
  82. }
Add Comment
Please, Sign In to add comment