Yash Bhardwaj Yash Bhardwaj - 1 year ago 224
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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download