如何在RecyclerView中处理粘贴标题装饰的点击?

时间:2016-01-14 16:58:24

标签: header android-recyclerview decorator sticky

我有RecyclerView StickyHeaderDecor(内有ButtonImageViewTextView

如何在StickyHeader

中处理这些组件的点击次数

library used is UltimateRecyclerView

这是我设置recyclerView的代码:

    StickyRecyclerHeadersDecoration headersDecoration =
            new StickyRecyclerHeadersDecoration(adapter);
    recyclerView.addItemDecoration(headersDecoration);
    StickyRecyclerHeadersTouchListener headersTouchListener =
            new StickyRecyclerHeadersTouchListener(recyclerView, headersDecoration);
    headersTouchListener.setOnHeaderClickListener(new StickyRecyclerHeadersTouchListener.OnHeaderClickListener() {
        @Override
        public void onHeaderClick(View headerView, int position, long headerId) {
            Log.d(TAG, "clicked view " + v.getId() + " position:" + position);

            // my code here to handle click (*)
        }
    });
    recyclerView.addOnItemTouchListener(headersTouchListener);

(*)我无法处理点击headerView

1 个答案:

答案 0 :(得分:1)

不幸的是,不可能轻松处理部分项目装饰的点击。 Here解释了原因。

对于Sticky Headers更好用: