Reputation: 7527
How do i listen for touch events in a recycler view?I have implemented click listener for the view holder but this works on the entire view.I have an image view in each view holder and when the user clicks on an image view i need to perform an action.
public class ViewHolder_Custom extends RecyclerView.ViewHolder implements View.OnClickListener {
private TextView name;
private ImageView image_path;
private static ClickListener clickListener_custom;
public ViewHolder_Custom(View itemView) {
super(itemView);
name = (TextView) itemView.findViewById(R.id.name);
image_path = (ImageView) itemView.findViewById(R.id.image);
itemView.setOnClickListener(this);
}
public TextView getName() {
return name;
}
@Override
public void onClick(View view) {
if (clickListener_custom != null) {
clickListener_custom.itemClick(view, getAdapterPosition());
}
}
public ImageView getImage_path() {
return image_path;
}
public interface ClickListener {
void itemClick(View v, int position);
}
public static void setClickListener(ClickListener clickListener) {
ViewHolder_Custom.clickListener_custom = clickListener;
}
}
Current View Holder code.
Upvotes: 1
Views: 2247
Reputation: 8538
Since you want to perform action when click every imageview in an item,you can add onClickListener for your imageview of each viewholder.According to the order of performing touch listener,your imageview's listener will perform before the listener added to viewholder.view.
Upvotes: 1