首先,我为onTouchListener
设置recyclerView
。
recyclerview.setOnTouchListener(this);
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
System.out.println("action_down");
if (layoutManager instanceof GridLayoutManager) {
GridLayoutManager g = ((GridLayoutManager) layoutManager);
System.out.println("findFirstVisibleItemPosition = " + g.findFirstVisibleItemPosition());
if (g.findFirstVisibleItemPosition() == 0) {
isTop = true;
startY = (int) event.getY();
}
} else if (layoutManager instanceof LinearLayoutManager) {
LinearLayoutManager l = (LinearLayoutManager) layoutManager;
System.out.println("findFirstVisibleItemPosition = " + l.findFirstVisibleItemPosition());
if (l.findFirstVisibleItemPosition() == 0) {
isTop = true;
startY = (int) event.getY();
}
}
}
break;
case MotionEvent.ACTION_MOVE: {
System.out.println("action_move");
}
break;
case MotionEvent.ACTION_UP: {
System.out.println("action_up");
if (state == RELEASE) {
state = REFRESHING;
refreshState();
listener.onRefreshing();
} else if (state == PULL) {
state = NORMAL;
isTop = false;
resetRefresh(paddingBottom, -headerRefreshHeight, 400);
}
}
break;
}
return false;
}
我在适配器的onClickListener()
方法
childView
RecyclerView
设置了onBindViewHolder()
@Override
public void onBindViewHolder(RViewHolder holder, final int position) {
final int pos = position;
if (onItemClickListener != null) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onItemClickListener.onItemClick(v, pos);
}
});
}
if (onItemLongClickListener != null) {
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return onItemLongClickListener.onItemLongClickListener(v, position);
}
});
}
convert(holder, data.get(position));
}
最后在onTouch()
函数中,不再有action_down MotionEvent
。
我弄清楚了。谁知道呢?非常感谢提前!