@ Override public void onBindViewHolder ( final VH vh , final int i ) { if ( itemClickListener != null ) { vh . itemView . setOnClickListener ( new View . OnClickListener ( ) { @ Override public void onClick ( View v ) { int position = vh . getAdapterPosition ( ) ; if ( position != RecyclerView . NO_POSITION ) { itemClickListener . onItemClick ( v , getItem ( position ) , position ) ; } } } ) ; } if ( itemLongClickListener != null ) { vh . itemView . setOnLongClickListener ( new View . OnLongClickListener ( ) { @ Override public boolean onLongClick ( View v ) { int position = vh . getAdapterPosition ( ) ; if ( position != RecyclerView . NO_POSITION ) { return itemLongClickListener . onItemLongClick ( v , getItem ( position ) , position ) ; } return false ; } } ) ; } }
Intercept the bind View holder method to wire up the item click listener only if the listener is set by the user