我正在使用 ItemTouchHelper 和 ItemTouchHelper.SimpleCallback 来允许用户重新排序垂直列表 Recycler View。
拖放有效,但在第一条跳线之后强制下降,即使我没有将手指从拖动的单元格中移开。
请在 SimpleCallback 下面找到:
private void initSwipeAndDrap() {
ItemTouchHelper.SimpleCallback simpleItemTouchCallback =
new ItemTouchHelper.SimpleCallback(
ItemTouchHelper.UP | ItemTouchHelper.DOWN,
0) {
//========== Swipe (Not used) ==============
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
}
//========== Drag ==============
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
int fromPosition = viewHolder.getAdapterPosition();
int toPosition = target.getAdapterPosition();
Podcast podcast = rva.podcasts.remove(fromPosition);
rva.podcasts.add(toPosition, podcast);
act.dmo.updatePodcastsListPosition();
act.dmo.notifyDataSetChangedPodcast();
return true;
}
@Override
public boolean isLongPressDragEnabled() {
return false;
}
};
itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
itemTouchHelper.attachToRecyclerView(rv);
}