You can do that by below code;
public class MyAdapter extends RecyclerView.Adapter {
private String[] mDataset;
public static class MyViewHolder extends RecyclerView.ViewHolder{
public CardView mCardView;
public TextView mTextView;
public View mainView;
public MyViewHolder(View v){
super(v);
mainView = v;
mCardView = (CardView) v.findViewById(R.id.card_view);
mTextView = (TextView) v.findViewById(R.id.tv_text);
}
}
public MyAdapter(String[] myDataset){
mDataset = myDataset;
}
@Override
public MyAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_item, parent, false);
MyViewHolder vh = new MyViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(MyViewHolder holder, final int position){
holder.mTextView.setText(mDataset[position]);
//And below code will execute item click event for RecyclerView's item....
holder.mainView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Do your code here for item click ....
}
});
}
@Override
public int getItemCount() { return mDataset.length; }
}