防止双击底部片段,当我双击时显示两次

问题描述 投票:0回答:2

您有一个底部对话框对话框片段,当单击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;
                }

现在出现的问题是,当我单击该项目时,有时没有任何反应,然后再次单击该项目后,它将显示完全没有出现]]

您有一个底部对话框对话框片段,当单击recyclerview中的项目时将显示该片段。底层实现的显示在用于recyclerview的适配器中。问题...

android android-studio bottom-sheet android-bottomsheetdialog
2个回答
0
投票

有很多方法可以做到这一点,一种方法是将bottomSheetFragment保存在一个字段中,并在显示之前检查它是否已显示


0
投票

您可以使用RxView进行控制,例如RxView.clicks(myViewHolder.cardView).throttle(2,TimeUnit.SECONDS).subscribe {

© www.soinside.com 2019 - 2024. All rights reserved.