Yash Bhardwaj Yash Bhardwaj - 3 months ago 44
Android Question

Dialog Open on Recycler view Row button click

In Recycler View I click on a button add to cart a dialog is open.

Please let me know how this will be implemented
Please Refer Image


First create an inner class ViewHolder likes below:

private class MyViewHolder extends RecyclerView.ViewHolder {
    public Button btnCart;

    public MyViewHolder(View view) {
        btnCart = (Button) view.findViewById(R.id.btnCart);

Then override onBindViewHolder in your adapter (your adapter extends RecyclerView.Adapter).

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

        holder.btnCart.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // call open your dialog here