一、所需第三方库
BaseRecyclerViewAdapterHelper
二、直接上代码
直接在RecyclerView Item xml里面写一个遮罩,通过点击事件处理
OnItemTouchListener事件拦截
通过继承BaseRecyclerViewAdapterHelper里面的SimpleClickListener实现,其他点击事件只需在Adapter里实现。
class XSimpleClickListener extends SimpleClickListener {
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
if (e.getAction() == MotionEvent.ACTION_DOWN) {//按下
//获取点击ItemView
View child = rv.findChildViewUnder(e.getX(), e.getY());
if (child != null && rv.getChildAdapterPosition(child) == adapter.getCurLongPosition()) {
//获取点击Position
int clickPosition = rv.getChildAdapterPosition(child);
//获取记录在Adapter里面的长按Position
int longPosition = adapter.getCurLongPosition();
if (clickPosition == longPosition) {
//通过SimpleClickListener把点击事件传递到子View
return super.onInterceptTouchEvent(rv, e);
} else {
//隐藏所需View,且不做拦截
adapter.hideCurLLDelete();
return false;
}
} else {
//隐藏所需View,且不做拦截
adapter.hideCurLLDelete();
return false;
}
}
return super.onInterceptTouchEvent(rv, e);
}
@Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
}
@Override
public void onItemLongClick(BaseQuickAdapter adapter, View view, int position) {
}
@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
}
@Override
public void onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) {
}
}
三、好了就到这了,需要使用里面的点击事件可以去查看BaseRecyclerViewAdapterHelper使用说明
BaseRecyclerViewAdapterHelper官网:https://github.com/CymChad/BaseRecyclerViewAdapterHelper
网友评论