您好,我有一个底部工作表对话框片段,当单击 recyclerview 中的项目时会显示该片段。底部工作表实现的显示在 recyclerview 的适配器中。遇到的问题是,当您快速双击项目以显示底部工作表时,它会显示两次,有没有办法将点击限制为仅单击一次,或者在显示底部工作表对话框片段时不再显示通过检查
这是在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;
}
现在出现的问题是,有一段时间当我单击该项目时完全没有任何反应,然后在我再次单击该项目后它显示