如何禁用按钮并清除数组列表?

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

我有一些按钮和数组列表,我的按钮有条件

if(list.isEmpty){ 
   button.setEnabled(false)  
} 

并且textTotalFinalPrice将值设置为0

但是在我的情况下,实际起作用的功能[[BUT必须单击两次以设置值textTotalFinalPrice,然后禁用button

如果仅单击1则ArrayList不会清除数据

我尝试list.clear();仍然无法正常工作

代码:

public void calculateTotalPrice(){ activity.header.grandTotalPrice(); activity.textTotalFinalPrice.setText(NumberFormat.getCurrencyInstance(new Locale("id", "id")).format(activity.header.getFinalTotal())); } private void conditionCartsSize() { if (activity.header.getCarts().isEmpty()){ activity.textFinishOrder.setEnabled(false); }else{ activity.textFinishOrder.setEnabled(true); activity.textFinishOrder.setOnClickListener(view -> { PrintHelper.bluetoothPrint(activity, activity.header); calculateTotalPrice(); AlertDialog dialog = new AlertDialog.Builder(activity) .setTitle("Pesanan Berhasil") .setMessage("Silahkan Ambil Struk Anda") .create(); dialog.show(); activity.header.getCarts().removeAll(activity.header.getCarts()); notifyDataSetChanged(); }); } }

我将不胜感激您的回答
java android list conditional-statements clear
1个回答
0
投票
如果满足以下条件,请检查sizegetCarts()

private void conditionCartsSize() { if (activity.header.getCarts().size>0){ activity.textFinishOrder.setEnabled(false); }else{ activity.textFinishOrder.setEnabled(true); activity.textFinishOrder.setOnClickListener(view -> { PrintHelper.bluetoothPrint(activity, activity.header); calculateTotalPrice(); AlertDialog dialog = new AlertDialog.Builder(activity) .setTitle("Pesanan Berhasil") .setMessage("Silahkan Ambil Struk Anda") .create(); dialog.show(); activity.header.getCarts().removeAll(activity.header.getCarts()); notifyDataSetChanged(); }); } }

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