aka Mishu
aka Mishu

Reputation: 39

Main activity doesn't update the content when the adapter makes an action

I have an activity that has an adapter , in the adapter I have a plus button and a counter near it , when i press the button the counter doesn't update . In the activity i have a total sum that goes like: price*count , but it doesn't update either . Basically any action that i am doing in the adapter it doesn't notify my main activity ..

I tried to make the load main activity method public but it can't be accesed by the adapter

Some of the adapter class :

  public void onBindViewHolder(final CartViewHolder holder, final int position) {

    String price = (Integer.parseInt(String.valueOf(listData.get(position).getPret()))) + " RON" ; /* * (Integer.parseInt(listData.get(position).getQuantity())); */
    holder.txt_price.setText((price));
    holder.txt_cart_name.setText(listData.get(position).getDenumireProdus());
    holder.img_cart_count.setText(String.valueOf(listData.get(position).getCantitate()));



    if(listData.get(position).getCantitate() <  (1))
    {
        new Database(context).removeFromCart(FirebaseAuth.getInstance().getCurrentUser().getUid(),listData.get(position).getDenumireProdus());
    }


    holder.minus_cantitate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new Database(context).minusCantitate(FirebaseAuth.getInstance().getCurrentUser().getUid(),listData.get(position).getDenumireProdus());


        }
    });
    holder.plus_cantitate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new Database(context).plusCantitate(FirebaseAuth.getInstance().getCurrentUser().getUid(),listData.get(position).getDenumireProdus());

        }
    });
}

This is the main activity load method :

 private void loadListFood() {

    cart = new Database(this).getCarts(FirebaseAuth.getInstance().getCurrentUser().getUid());
    adapter = new CartAdapter(cart,this);
    recyclerView.setAdapter(adapter);}

Upvotes: 0

Views: 32

Answers (1)

Mohamed Ashik
Mohamed Ashik

Reputation: 362

you can call activity method from adapter class using interface. Check this link:

https://stackoverflow.com/a/49969478/5482918

Upvotes: 1

Related Questions