javaandroidandroid-recyclerviewandroid-adapterrecreate

How to refresh an Activity from an Adapter in java


I have to update total price of the items selected in the cart activity by refreshing the activity when user updates the quantity of the items selected

Total price method is in the MainActivity while the cart items selected is in the RecyclerView

Just want to refresh an activity from adapter

public class Cart extends AppCompatActivity {

......

public void refreshActivtiy(){
            recreate();
    }
}

//Adapter

public class CartAdapter extends RecyclerView.Adapter<CartAdapter.CartViewHolder> {

    public void onBindViewHolder(@NonNull final CartAdapter.CartViewHolder holder, final int position) {

Cart cart = new Cart();
cart.refreshActivity();
}
}

Not working!!!


Solution

  • Solution

    ((Cart)context).refreshActivtiy();