I have problem with RecyclerView, because when I long press on view, it results simple click. This is simple implementation of long click. Of course in my code I set this listeners to my Adapter.
public class HomeListAdapter extends RecyclerView.Adapter<HomeListAdapter<P>.ViewHolder> {
OnItemClickListener mItemClickListener;
OnItemLongClickListener mItemLongClickListener;
public HomeListAdapter() {
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
public ViewHolder(View itemView, int viewType) {
super(itemView);
}
@Override
public void onClick(View v) {
if (mItemClickListener != null) {
mItemClickListener.onItemClick(itemView, getPosition());
}
}
@Override
public boolean onLongClick(View v) {
if (mItemLongClickListener != null) {
mItemLongClickListener.onItemLongClick(itemView, getPosition());
return true;
}
return false;
}
}
public void setOnItemClickListener(final OnItemClickListener mItemClickListener) {
this.mItemClickListener = mItemClickListener;
}
public void setOnItemLongClickListener(final OnItemLongClickListener mItemLongClickListener) {
this.mItemLongClickListener = mItemLongClickListener;
}
}
public interface OnItemClickListener {
void onItemClick(View view, int position);
}
public interface OnItemLongClickListener {
void onItemLongClick(View view, int position);
}
public class HomeListOnItemClickListener implements OnItemClickListener{
@Override
public void onItemClick(View view, int position) {
Log.d("Test", "Click");
}
}
public class HomeListOnItemLongClickListener implements OnItemLongClickListener{
@Override
public void onItemLongClick(View view, int position) {
Log.d("Test", "Long Click");
}
}
Every help will be appreciated.