我有一些按钮和数组列表,我的按钮有条件
if(list.isEmpty){
button.setEnabled(false)
}
并且textTotalFinalPrice
将值设置为0
但是在我的情况下,实际起作用的功能[[BUT必须单击两次以设置值textTotalFinalPrice
,然后禁用button
。
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();
});
}
}
我将不胜感激您的回答
size
的getCarts()
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();
});
}
}