Kevin Roberts Kevin Roberts - 3 months ago 15
Android Question

How to implement click listener in recyclerview?

I am new in android and learning about RecyclerView. I am working with json so that i can get data from server. I followed this tutorial for this. I am not getting how to implement onclicklistner on my recyclerview.

Answer

Following your tutorial, on the "bind data" method you can set a click listener. It will as easy as writing:

holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
        // write your code here
        }

    });

You will also need to change the

int position

to final, like:

@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder,final int position) {