So the problem is the onClick only gets called for the imageButton and not the while itemView. Here is my ViewHolder Class
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
protected TextView title;
protected TextView rank;
protected ImageView image;
protected ImageButton share;
public ViewHolder(View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.main_title);
rank = (TextView) itemView.findViewById(R.id.rank_text);
image = (ImageView) itemView.findViewById(R.id.main_image);
share = (ImageButton) itemView.findViewById(R.id.main_share);
share.setOnClickListener(this);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Log.d("click", "clicked at" + getAdapterPosition());
}
}
UPDATE:
Because I was using cardviews in my recycleview, I ended up changing my viewholder code to this
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
protected TextView title;
protected TextView rank;
protected ImageView image;
protected ImageButton share;
protected CardView cardView;
public ViewHolder(View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.main_title);
rank = (TextView) itemView.findViewById(R.id.rank_text);
image = (ImageView) itemView.findViewById(R.id.main_image);
share = (ImageButton) itemView.findViewById(R.id.main_share);
cardView = (CardView) itemView.findViewById(R.id.main_card_view);
share.setOnClickListener(this);
cardView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Log.d("test", "test" + getAdapterPosition());
}
}
And it works