Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Adapter saved data
- String key = "Key";
- List<CartProductListPojo> cartProductListPojos = new ArrayList();
- cartProductListPojos.add(new CartProductListPojo( getItemId.getProductImage(),
- getItemId.getProductName(),
- getItemId.getProductBrandName(), getItemId.getProductCategory(), 1,
- getItemId.getProductPrice()));
- SharedPreferences shref;
- SharedPreferences.Editor editor;
- shref = context.getSharedPreferences("Name", Context.MODE_PRIVATE);
- Gson gson = new Gson();
- String json = gson.toJson(cartProductListPojos);
- editor = shref.edit();
- /*editor.remove(key).commit();*/
- editor.putString(key, json);
- editor.commit();
- //CartActivity retrieve data
- SharedPreferences sharedPreferences = getSharedPreferences("Name", MODE_PRIVATE);
- String key = "Key";
- Gson gson = new Gson();
- String response = sharedPreferences.getString(key, "");
- List<CartProductListPojo> cartProductListPojo = gson.fromJson(response,
- new TypeToken<List<CartProductListPojo>>() {}.getType());
- for (int i = 0; i < cartProductListPojo.size(); i++){
- productsName = cartProductListPojo.get(i).getProductName();
- Toast.makeText(this, productsName, Toast.LENGTH_SHORT).show();
- cartProductListPojos.add(new CartProductListPojo(productsImage, productsName,
- productsBrandName, productsCategory, 1, productsPrice));
- cartProductListAdapter = new CartProductListAdapter(this, cartProductListPojos);
- recyclerView.setLayoutManager(new LinearLayoutManager(this));
- recyclerView.setAdapter(cartProductListAdapter);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement