Guest User

Untitled

a guest
Feb 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. public PlaceholderFragment() {
  2. }
  3.  
  4. public static PlaceholderFragment newInstance(int position) {
  5. PlaceholderFragment fragment = new PlaceholderFragment();
  6. String itemTitle = foodItemTitle.get(position);
  7. String itemPrice = foodItemPrice.get(position);
  8. String itemImage = foodItemImage.get(position);
  9.  
  10. Bundle args = new Bundle();
  11. args.putString("ITEMS", itemTitle);
  12. args.putString("PRICE", itemPrice);
  13. args.putString("IMAGE", itemImage);
  14. fragment.setArguments(args);
  15. return fragment;
  16. }
  17. public static void setContext( Activity activity) {
  18. context = activity;
  19. }
  20. @Override
  21. public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
  22. View rootView = inflater.inflate(R.layout.fragment_items_list, container, false);
  23. img = (ImageView) rootView.findViewById(R.id.section_label);
  24. pricePerItem = rootView.findViewById(R.id.price);
  25. nutri = rootView.findViewById(R.id.itemName);
  26. removeBtn=rootView.findViewById(R.id.removebtn);
  27. addBtn=rootView.findViewById(R.id.addBtn);
  28. quantity=rootView.findViewById(R.id.qty);
  29. String items = getArguments().get("ITEMS").toString();
  30. final String price = getArguments().get("PRICE").toString();
  31. String image = getArguments().get("IMAGE").toString();
  32. setItemDetails(items, price, image);
  33. addBtn.setOnClickListener(new View.OnClickListener() {
  34. @Override
  35. public void onClick(View view) {
  36. countTtl = count + 1;
  37. int curntQty = Integer.parseInt(quantity.getText().toString()) + 1;
  38. Toast.makeText(getContext(), String.valueOf(curntQty), Toast.LENGTH_SHORT).show();
  39. quantity.setText(String.valueOf(curntQty));}});
  40. removeBtn.setOnClickListener(new View.OnClickListener() {
  41. @Override
  42. public void onClick(View view) {
  43. if (quantity.getText().toString().equals("0")) {
  44.  
  45. Toast.makeText(getContext(), "Add Item First", Toast.LENGTH_SHORT).show();
  46.  
  47. } else {
  48.  
  49. int qtyTtl = Integer.parseInt(quantity.getText().toString()) - 1;
  50.  
  51. quantity.setText(String.valueOf(qtyTtl));
  52. Toast.makeText(getContext(), quantity.getText().toString(), Toast.LENGTH_SHORT).show(); }
  53. }
  54. });
  55. return rootView;
  56. }
  57. }
Add Comment
Please, Sign In to add comment