UI问题 - 滑动以删除Android中的RecyclerView

时间:2018-05-21 08:35:45

标签: android view android-recyclerview delete-row

我遇到的回收站视图问题无法在用户删除项目时正确更新UI。数据已删除,但它仍将是UI上的空行。请救我脱离黑暗。谢谢。

删除后

这是代码

mRecyclerView.setAdapter(mAdapter);
        

        ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
            @Override
            public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
                return false;
            }

            @Override
            public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {


                final int position = viewHolder.getAdapterPosition();

                listData.remove(position);
                mAdapter.notifyItemRemoved(position);


            }
        };

        ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
        itemTouchHelper.attachToRecyclerView(mRecyclerView);

0 个答案:

没有答案