// 適配器繼承
public class EditDataCenterAdapter extends BaseItemDraggableAdapter<Bean, BaseViewHolder>{
}
// 代碼中設(shè)置綁定適配器
mAdapter = new EditDataCenterAdapter(mList);
mRvList.setLayoutManager(new LinearLayoutManager(this));
mRvList.setAdapter(mAdapter);
ItemDragAndSwipeCallback itemDragAndSwipeCallback = new ItemDragAndSwipeCallback(mAdapter);
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemDragAndSwipeCallback);
itemTouchHelper.attachToRecyclerView(mRvList);
// 設(shè)置可拖拽(rl_layout: item的根布局id)
mAdapter.enableDragItem(itemTouchHelper, R.id.rl_layout, true);
mAdapter.setOnItemDragListener(onItemDragListener);
onItemDragListener
OnItemDragListener onItemDragListener = new OnItemDragListener() {
@Override
public void onItemDragStart(RecyclerView.ViewHolder viewHolder, int pos) {
}
@Override
public void onItemDragMoving(RecyclerView.ViewHolder source, int from, RecyclerView.ViewHolder target, int to) {
}
@Override
public void onItemDragEnd(RecyclerView.ViewHolder viewHolder, int pos) {
}
};