SocialSupaCrew SocialSupaCrew - 1 year ago 156
Android Question

Multiple onClickListener in a RecyclerView

I have a RecyclerView with multiple items. Each Item have multiple button to do some actions.
So I have implemented the View.OnClickListener to my RecyclerViewAdapter.

But it's seems like I can only set one OnClickListener in the onCreateViewHolder function.

Does anyone know any solution to have multiple button in each items of my RecyclerView ?

Answer Source

You could implement OnClickListener and inside onClick function implement each action. Like this.

static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    Button button1;
    Button button2;
    Button button3;
    Button button4;

    public MyViewHolder(View itemView) {
        button1 = (Button) itemView.findViewById(;
        button2 = (Button) itemView.findViewById(;
        button3 = (Button) itemView.findViewById(;
        button4 = (Button) itemView.findViewById(;


    public void onClick(View view) {
        if (view == button1) {
            // button1 action
        } else if (view == button2) {
            // button2 action
        } else if (view == button3) {
            // button3 action
        } else if (view == button4) {
            // button4 action
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download