0

I have a fragment holds a recyclerview and textview so i want to call a method which i declared in the fragment inside the recyclerview adapter because i have a plus button in each recyclerview item so when i click on it the method will being called so the textview which is in the fragment change its value.

Fragment code

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {


    View view = inflater.inflate(R.layout.fragment_cart, container, false);

    ItemsAddedToCart = view.findViewById(R.id.itemsAddRV);
    Total = view.findViewById(R.id.TotalPrice);


    fillCart = new FillCart(c,cartList);
    ItemsAddedToCart.setAdapter(fillCart);
    ItemsAddedToCart.setLayoutManager(new LinearLayoutManager(c));


    return view;
}

fragment method

public void updateTotal()
{
    Total.setText(fillCart.Total());
}

ADAPTER

adapter method

public String Total()
{
    return String.valueOf(price * Qt);
}

plus button

((ViewHodler)holder).plusBut.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            price = Integer.parseInt(((ViewHodler)holder).price.getText().toString());
            Qt = Integer.parseInt(((ViewHodler)holder).quantity.getText().toString());
            Qt++;`

            // FRAGMENT METHOD WILL CALLED HERE
        }
    });

1 Answers1

0

As Hassan Tareq say: Use this concept - > https://developer.android.com/training/basics/fragments/communicating

Paulo César
  • 451
  • 3
  • 7