Android-RecyclerView: handle item click event

One way to handle Item click event while using RecyclerView is to specify the handler inside the constructor of the ViewHolder inside the Adapter class.

Like this:

/*Adapter class*/
private class MyRecyclerAdapter extends RecyclerView.Adapter<MyRecyclerAdapter.ViewHolder>{ //item = ViewHolder type
    private List<Country> countryData;
    private Context context;
    /*Constructor of the adapter class*/
    public MyRecyclerAdapter (List<Country> data,Context context){
        this.context = context;
        this.countryData = data;

    public class ViewHolder extends RecyclerView.ViewHolder /*implements View.OnClickListener*/{
        public TextView tvName;
        public TextView tvRank;
        public TextView tvPop;
        public ImageView ivFlag;
        View itemCountry;

        /*Constructor of the ViewHolder*/
        public ViewHolder(View itemCountry){
            tvName =(TextView) itemCountry.findViewById(;
            tvRank = (TextView) itemCountry.findViewById( ;
            tvPop = (TextView) itemCountry.findViewById(;
            ivFlag = (ImageView) itemCountry.findViewById(;
        /*HERE: Event handler*/
            itemCountry.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                         /*TODO: Do what you want here*/