How can I set a listener inside a RecyclerView Header Decor?

前端 未结 1 552
伪装坚强ぢ
伪装坚强ぢ 2020-12-12 04:31

I implemented sticky headers in my RecyclerView, using this library

I want to add a clickable view inside the custom header, but when I set the listener in the

相关标签:
1条回答
  • 2020-12-12 05:02

    EDIT of 29/03/2016: Sticky Headers are now clickable using same listeners of the ViewHolder, not using anymore ItemDecoration. A FrameLayout is instead used.

    Answer: I've worked on header-decor and on sticky-headers-recyclerview and my conclusion is that, ItemDecoration should not be the way to implement a real good sticky headers, because what we have is just something drawn on the top and is not a view(!) so we cannot attach any listener on that thing and we cannot interact with that thing.

    But... I was able, in my FlexibleAdapter project, to intercept the tap on the sticky header, now it is become an advanced solution for this functionality.

    See my comments here:

    • https://github.com/timehop/sticky-headers-recyclerview/issues/105#issuecomment-187144374
    • https://github.com/davideas/FlexibleAdapter/issues/41

    Another very important note:

    The 2 projects, I mentioned on the top, make heavy use of cycle for statement: they draw, as a "decoration" many times on the top of the items (with onDrawOver), all the headers currently displayed. Not only, they put in a cache ALL the views and the reference to the positions without recycling(!) them.

    You can imagine how much the memory increases and how much work the phone is making every time the list is scrolled of every pixel, with a huge battery consummation... Huh... I have removed all these things in the new StickyHeaderHelper.

    0 讨论(0)
提交回复
热议问题