UltimateRecyclerView icon indicating copy to clipboard operation
UltimateRecyclerView copied to clipboard

onclick in sticky header

Open cielantropi opened this issue 9 years ago • 4 comments

Hi, How can I add an onClick in the sticky header? i tried to add it on the onBindHeaderViewHolder.. its not working. Thanks.

cielantropi avatar Jun 04 '15 05:06 cielantropi

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.

jensneuse avatar Jun 16 '15 16:06 jensneuse

how about the code implemented here

jjhesk avatar Jul 01 '15 04:07 jjhesk

@jjhesk do you have usage example of StickyRecyclerHeadersTouchListener ? UPD: I have found the way how to do it. Testing it now.

sergii-frost avatar Jul 16 '15 14:07 sergii-frost

I have implemented StickyRecyclerHeadersTouchListener in the demo app but it does not work.

tajoumal avatar May 08 '19 10:05 tajoumal