Hello,我有一个底部页对话框片段,当一个回收视图中的一个项目被点击时显示出来。 底部工作表实现的显示在RecycerView的适配器中。 我的问题是,当您快速地双击项目以显示它显示两次的底部工作表时,有没有一种方法限制只点击一次或不显示底部工作表对话框片段,当它通过检查显示时
下面是我如何在回收器视图中显示点击项目的底部页
@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());
}
});
}
有很多方法可以做到这一点,其中一种方法是将bottomSheetFragment保存在字段中,并在显示它之前检查它是否正在显示
BottomSheetFragment bottomSheetFragment = new BottomSheetFragment();
@Override
public void onBindViewHolder(@NonNull final MyViewHolder myViewHolder, final int position) {
myViewHolder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(bottomSheetFragment.isAdded()) return
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.showNow(fragmentManager, bottomSheetFragment.getTag());
}
});
}