你好,我正在使用底部弹出的对话框碎片(Bottom Sheet Dialog Fragment),当点击recyclerview中的项目时会显示该碎片。在适配器中实现底部弹出的代码。问题是,如果快速双击项目,则会显示两次底部弹出的对话框碎片,是否有办法限制仅允许单击一次或者检查已显示弹出窗口而不再显示?以下是显示底部弹出对话框的处理方式:
@Override
public void onBindViewHolder(@NonNull final MyViewHolder myViewHolder, final int position) {
myViewHolder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BottomSheetFragment bottomSheetFragment = new BottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putInt("id",productList.get(position).getId());
bundle.putString("name",productList.get(position).getName());
bundle.putDouble("price",productList.get(position).getPrice());
bundle.putInt("stock",productList.get(position).getStock());
bundle.putInt("quantity",productList.get(position).getQuantity());
bundle.putString("photo",productList.get(position).getPhoto());
bottomSheetFragment.setArguments(bundle);
bottomSheetFragment.show(fragmentManager, bottomSheetFragment.getTag());
}
});
}
我已经尝试使用Muhannad Fakhouri的答案,按以下步骤进行:
声明一个布尔值以显示BottomSheet是否正在显示
private boolean isBottomSheetShowing = false;
底部工作表的实现
if(!isBottomSheetShowing){
isBottomSheetShowing = true;
ItemBottomSheet itemBottomSheet = new ItemBottomSheet();
Bundle bundle = new Bundle();
bundle.putString("code",itemPosition.getCode());
bundle.putString("name",itemPosition.getName());
bundle.putString("description",itemPosition.getDescription());
bundle.putString("upcCode",itemPosition.getUpcCode());
bundle.putString("photoBlob",itemPosition.getPhotoBlob());
bundle.putDouble("discount",itemPosition.getDiscount());
bundle.putDouble("price",itemPosition.getPrice());
bundle.putInt("available",itemPosition.getAvailable());
itemBottomSheet.setArguments(bundle);
itemBottomSheet.show(fragmentManager, itemBottomSheet.getTag());
}else{
isBottomSheetShowing = false;
}
现在出现的问题是,有时我点击该项目时什么也不会发生,然后再次点击该项目后它才会显示。