RecyclerView:notifyItemRemoved()

时间:2016-07-07 21:24:26

标签: java android android-recyclerview

行为视频:https://vid.me/nF1J

卸下:

viewHolder.buttonDelete.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        mItemManger.removeShownLayouts(viewHolder.swipeLayout);
        mDataset.remove(position);
        notifyItemRemoved(position);
        notifyItemRangeChanged(position, mDataset.size());
        mItemManger.closeAllItems();
        Toast.makeText(view.getContext(), "Deleted " + viewHolder.textViewPos.getText().toString() + "!", Toast.LENGTH_SHORT).show();
    }
});

我该如何解决这个问题?

备注: 我使用this library,我更新了库。

更新

viewHolder.buttonDelete.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        mItemManger.removeShownLayouts(viewHolder.swipeLayout);
        mResultArray.remove(position);
        notifyItemRangeChanged(position, mResultArray.size());
        notifyItemRemoved(position);
        mItemManger.closeAllItems();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                notifyDataSetChanged();
            }
        }, 500);
    }
});

2 个答案:

答案 0 :(得分:6)

RecyclerView必须有layout_height="match_parent"。如果最后一个项目的问题消失并再次出现让我发疯。

答案 1 :(得分:1)

我认为你应该拨打notifyItemRangeRemoved(position, 1);