UltimateRecyclerView
UltimateRecyclerView copied to clipboard
onclick in sticky header
Hi, How can I add an onClick in the sticky header? i tried to add it on the onBindHeaderViewHolder.. its not working. Thanks.
public class UltimateRecyclerViewOnItemTouchListener implements RecyclerView.OnItemTouchListener {
private OnItemClickListener mListener;
private StickyRecyclerHeadersDecoration decoration;
private RecyclerView recyclerView;
public interface OnItemClickListener {
void onItemClick(View view,MotionEvent motionEvent, int position);
}
GestureDetector mGestureDetector;
public UltimateRecyclerViewOnItemTouchListener(Context context, StickyRecyclerHeadersDecoration decoration, RecyclerView recyclerView, OnItemClickListener listener) {
this.recyclerView = recyclerView;
this.decoration = decoration;
mListener = listener;
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
});
}
@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
if (mGestureDetector.onTouchEvent(e)) {
int position = decoration.findHeaderPositionUnder((int) e.getRawX(), (int) e.getY());
if (position != -1) {
View headerView = decoration.getHeaderView(recyclerView, position);
mListener.onItemClick(headerView,e,position);
return true;
}
}
return false;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
}
You tell me if this approach is clean or hacky. For me it works. Glad if you guys have a better idea. Do whatever you like to do with it.
how about the code implemented here
@jjhesk do you have usage example of StickyRecyclerHeadersTouchListener
?
UPD: I have found the way how to do it. Testing it now.
I have implemented StickyRecyclerHeadersTouchListener in the demo app but it does not work.