racofix / architecture-for-android

🙈 Coroutines + flow + mvvm-clean / mvp
881 stars 239 forks source link

XRecyclerView 直接用core中的RecyclerAdapter 时 setOnItemClickListener时有个注意点 #12

Closed yanbin92 closed 7 years ago

yanbin92 commented 7 years ago

,XRecyclerView 有header 下段代码中 int position = getPosition(viewHolder); position应该-1 protected void setListener(final ViewGroup parent, final RecyclerViewHolder viewHolder, int viewType) { if (!isEnabled(viewType)) return; viewHolder.getConvertView().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mOnItemClickListener != null) { int position = getPosition(viewHolder); mOnItemClickListener.onItemClick(parent, v, mDatas.get(position), position); } } });

    viewHolder.getConvertView().setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            if (mOnItemClickListener != null) {
                int position = getPosition(viewHolder);
                return mOnItemClickListener.onItemLongClick(parent, v, mDatas.get(position), position);
            }
            return false;
        }
    });
}