Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public PlaceholderFragment() {
- }
- public static PlaceholderFragment newInstance(int position) {
- PlaceholderFragment fragment = new PlaceholderFragment();
- String itemTitle = foodItemTitle.get(position);
- String itemPrice = foodItemPrice.get(position);
- String itemImage = foodItemImage.get(position);
- Bundle args = new Bundle();
- args.putString("ITEMS", itemTitle);
- args.putString("PRICE", itemPrice);
- args.putString("IMAGE", itemImage);
- fragment.setArguments(args);
- return fragment;
- }
- public static void setContext( Activity activity) {
- context = activity;
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
- View rootView = inflater.inflate(R.layout.fragment_items_list, container, false);
- img = (ImageView) rootView.findViewById(R.id.section_label);
- pricePerItem = rootView.findViewById(R.id.price);
- nutri = rootView.findViewById(R.id.itemName);
- removeBtn=rootView.findViewById(R.id.removebtn);
- addBtn=rootView.findViewById(R.id.addBtn);
- quantity=rootView.findViewById(R.id.qty);
- String items = getArguments().get("ITEMS").toString();
- final String price = getArguments().get("PRICE").toString();
- String image = getArguments().get("IMAGE").toString();
- setItemDetails(items, price, image);
- addBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- countTtl = count + 1;
- int curntQty = Integer.parseInt(quantity.getText().toString()) + 1;
- Toast.makeText(getContext(), String.valueOf(curntQty), Toast.LENGTH_SHORT).show();
- quantity.setText(String.valueOf(curntQty));}});
- removeBtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (quantity.getText().toString().equals("0")) {
- Toast.makeText(getContext(), "Add Item First", Toast.LENGTH_SHORT).show();
- } else {
- int qtyTtl = Integer.parseInt(quantity.getText().toString()) - 1;
- quantity.setText(String.valueOf(qtyTtl));
- Toast.makeText(getContext(), quantity.getText().toString(), Toast.LENGTH_SHORT).show(); }
- }
- });
- return rootView;
- }
- }
Add Comment
Please, Sign In to add comment