i have some button and arraylist, my button have condition
if(list.isEmpty){ button.setEnabled(false) }
and textTotalFinalPrice
set value to 0
but in my case , that function actually working BUT must be have 2 click to set value textTotalFinalPrice
and disabling button
.
if just 1 click ArrayList
not clearing data
i have try
list.clear();
still not working
code :
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(); }); } }
i will be appreciate your answer
Advertisement
Answer
Try using list = new ArrayList<>();