滑动删除BRVAh所实现

  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) {}
    };

    OnItemSwipeListener onItemSwipeListener = new OnItemSwipeListener() {
        @Override
        public void onItemSwipeStart(RecyclerView.ViewHolder viewHolder, int pos) {}
        @Override
        public void clearView(RecyclerView.ViewHolder viewHolder, int pos) {}
        @Override
        public void onItemSwiped(RecyclerView.ViewHolder viewHolder, int pos) {}
        @Override
        public void onItemSwipeMoving(Canvas canvas, RecyclerView.ViewHolder viewHolder, float dX, float dY, boolean isCurrentlyActive) {
            // item 滑动的过程
            canvas.drawColor(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary));
        }
    };


    @Override
    public void responseMsg(Bean bean) {
        List data = bean.getData();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(linearLayoutManager);

        ItemDragAdapter itemDragAdapter = new ItemDragAdapter(data);
        recyclerView.setAdapter(itemDragAdapter);
        ItemDragAndSwipeCallback itemDragAndSwipeCallback = new ItemDragAndSwipeCallback(itemDragAdapter);
        ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemDragAndSwipeCallback);
        itemTouchHelper.attachToRecyclerView(recyclerView);

        //设置左滑右滑都可以删除
        itemDragAndSwipeCallback.setSwipeMoveFlags(ItemTouchHelper.START | ItemTouchHelper.END);
        // 开启拖拽
        itemDragAdapter.enableDragItem(itemTouchHelper, R.id.text_view, true);
        itemDragAdapter.setOnItemDragListener(onItemDragListener);

// 开启滑动删除
        itemDragAdapter.enableSwipeItem();
        itemDragAdapter.setOnItemSwipeListener(onItemSwipeListener);
        //添加动画
        itemDragAdapter.openLoadAnimation();



    }
package mynamelqs.bwei.com.mylqs.mvp.ui.activity;

import com.chad.library.adapter.base.BaseItemDraggableAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import mynamelqs.bwei.com.mylqs.R;
import mynamelqs.bwei.com.mylqs.mvp.contract.Bean;

class ItemDragAdapter extends BaseItemDraggableAdapter {
    public ItemDragAdapter(List data) {
        super(R.layout.layout_item,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, Bean.DataBean item) {
        helper.setText(R.id.text_view,item.getName());
    }
}

 

你可能感兴趣的:(滑动删除BRVAh所实现)