SocialSupaCrew SocialSupaCrew - 8 months ago 74
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 ?


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