Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
- }
- 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();
- }
- 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));
- } catch (JSONException e) {
- e.printStackTrace();
- }
- adapter = new HotDealAdapter(context,products);
- rvHotDeal.setLayoutManager(new GridLayoutManager(context,2));
- rvHotDeal.setAdapter(adapter);
- adapter.notifyDataSetChanged();
- 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));
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- adapter = new HotDealAdapter(context,products);
- rvHotDeal.setLayoutManager(new GridLayoutManager(context,2));
- rvHotDeal.setAdapter(adapter);
- implementation 'com.google.code.gson:gson:2.8.2'
- ArrayList<YourPOJO> itemlist = new ArrayList<>();
- {
- // Your code implementation of binding data to recyclerview :
- GsonBuilder gsonbuilder= new GsonBuilder();
- Gson gson=gsonbuilder.create();
- //response = its your json string from server
- itemList =gson.fromJson(response, new TypeToken<List<YourPOJO>>(){}.getType());
- yourAdapter = new YourAdapter(itemList);
- yourRecyclerview.setAdapter(yourAdapter);
- }
Add Comment
Please, Sign In to add comment