如何解决Android Recycler视图项目在滑动时消失
我具有以下实现ItemTouchHelperAdapter(link)的适配器。我已经在回收器视图中实现了此适配器,以便在向左或向右滑动时执行元素的移除。它的工作方式如下:在向左或向右滑动元素时,在将其从回收器视图中删除之前,它会显示一个对话框,您可以在其中确认或取消操作。问题是,当您单击“取消”或仅关闭模态时,元素将从屏幕上消失,而向左/向右滑动。
这是RecyclerAdapter的代码:
public class TeambuilderAdapter extends RecyclerView.Adapter<TeambuilderAdapter.ViewHolder> implements ItemTouchHelperAdapter {
///////////////Irrelevant code
@Override
public void onItemDismiss(int position) {
DialogInterface.OnClickListener dialogClickListener = (dialog,which) -> {
if (which == DialogInterface.BUTTON_POSITIVE) {
mData.remove(position);
notifyItemRemoved(position);
((PokemonTeambuilderTabActivity) mContext).refreshTeamList();
}
};
new AlertDialog.Builder(mContext)
.setTitle(mContext.getString(R.string.remove_team))
.setMessage(mContext.getString(R.string.remove_team_question))
.setPositiveButtonIcon(ContextCompat.getDrawable(mContext,R.drawable.ic_baseline_check_circle_14))
.setPositiveButton(mContext.getString(R.string.confirm),dialogClickListener)
.setNegativeButtonIcon(ContextCompat.getDrawable(mContext,R.drawable.ic_baseline_cancel_14))
.setNegativeButton(mContext.getString(R.string.decline),dialogClickListener)
.show();
}
我该如何解决?滑动后,我曾尝试调用notifyDataSetChanged,但是它不起作用。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。