我已经实现了ItemTouchHelper,用于在回收器视图中从上到下以及从下到上拖放项目

时间:2018-12-26 12:15:43

标签: android android-studio android-recyclerview

我已经实现了ItemTouchHelper,用于在滑动完成后设置从下到上,从上到下的拖放,然后它应该刷新列表。但是我必须刷新列表的回调方法不起作用。

当我滑动列表时,滑动完成后并没有呼叫onMovedonSwiped

ItemTouchHelper helper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN,0) {
            @Override
            public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder dragged, RecyclerView.ViewHolder target) {
                int position_dragged = dragged.getAdapterPosition();
                int position_target = target.getAdapterPosition();
              adapter.notifyItemMoved(position_dragged,position_target);
                return false;
            }

            @Override
            public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
                //Toast.makeText(getActivity(),"swiped",Toast.LENGTH_SHORT).show();
                adapter.notifyDataSetChanged();
            }

            @Override
            public void onMoved(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, int fromPos, @NonNull RecyclerView.ViewHolder target, int toPos, int x, int y) {
                super.onMoved(recyclerView, viewHolder, fromPos, target, toPos, x, y);
                adapter.notifyDataSetChanged();
            }
        });
        helper.attachToRecyclerView(null);
        helper.attachToRecyclerView(myRecyclerView);

0 个答案:

没有答案