gpt4 book ai didi

java - 如何修复 "double printing when I clicked twice on the pretty dialog button"

转载 作者:太空宇宙 更新时间:2023-11-04 09:37:28 24 4
gpt4 key购买 nike

我调试我的应用程序,然后尝试在漂亮的对话框按钮上快速单击两次,它会打印两次,我希望即使我单击两次,它也不会打印两次。

我尝试了错误处理程序代码,但它不起作用。

prettyDialog.addButton("YES",
R.color.navy_blue,
R.color.gold_yellow,
new PrettyDialogCallback() {
@Override
public void onClick() {

getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {

raw_serial = String.valueOf(Build.SERIAL);
serial_final = raw_serial.substring(raw_serial.length() - 7);

nf = new DecimalFormat("000000");

DateFormat dateFormat = new SimpleDateFormat("MMddyyyy");
Date date = new Date();
ticket_date = dateFormat.format(date).toString();

DateFormat datetimeformat = new SimpleDateFormat("HHmmss");
Date time = new Date();

ticket_time = datetimeformat.format(time).toString();
transaction_no = serial_final + ticket_date + ticket_time + nf.format(setting_last_transaction_no);
trace_no = merchant_code + serial_final + ticket_date + ticket_time + nf.format(ref_trace_no);
print_card_no = Cardno.substring(Cardno.length() - 4);
String print_balance;
print_balance = "P" + String.valueOf(Balance);
int balancespace = 0;
int balancelength = 0;
balancelength = print_balance.length();
balancespace = 13 - balancelength;
for (int j = 0; j < balancespace; j++) {
print_balance = " " + print_balance;
}
int print = PrinterInterface.open();
Log.e("print", String.valueOf(print));
int querystatus = PrinterInterface.queryStatus();
Log.e("querystatus", String.valueOf(querystatus));
DateFormat dateformatforprint = new SimpleDateFormat("MMM.dd,yyyy");
Date dateformatprint = new Date();
String datetoprint = dateformatforprint.format(dateformatprint).toString();
DateFormat timeformattoprint = new SimpleDateFormat("HH:mm");
Date timeformat = new Date();
String timetoprint = timeformattoprint.format(timeformat).toString();
String finalStation = "";
Log.e("asdasd", "asdasd");
if (print >= 0) {
byte[] arryTitle = null;
byte[] arryTrx = null;
byte[] arrySubtitle = null;
byte[] arryBody1 = null;
byte[] arryspace1 = null;
byte[] arryFooter = null;
//test
try {
arryTitle = ("\n" + "TRIPKO" + "\n" + "\n").getBytes("UTF-8");
arryTrx = ("TRX: " + transaction_no + "\n" +
trace_no + "\n").getBytes("UTF-8");
arrySubtitle = ("Date & Time : " + datetoprint + " " + timetoprint + "\n" +
"Merchant Name: " + subcompany_name.toUpperCase() + "\n" +
"Branch : " + terminal_name.toUpperCase() + "\n" +
"-------------------------------" + "\n" +
"\n").getBytes("UTF-8");
arryBody1 = ("Card No. : " + " **** **** **** " + print_card_no + "\n" +
"Trans Type : " + " " + type_name.toUpperCase() + "\n" +
"Current Balance : " + print_balance + "\n" +
"-------------------------------" + "\n" +
"\n").getBytes("UTF-8");
arryFooter = ("Customer Service" + "\n"
+ "Hotline#: TRIPKO(678-1234)" + "\n" +
"\n").getBytes("UTF-8");
arryspace1 = "\n".getBytes("UTF-8");
} catch (Throwable e) {

e.printStackTrace();
}
begin();
if (querystatus == 1) {

writeLineBreak(20);
write(arryspace1);
alignment(1);
Fontsize(16);
boldFont(2);
doublewidth();
write(arryTitle);
backtonormal();
nextline();

Fontsize(0);
write(arryTrx);
alignment(0);
write(arrySubtitle);
write(arryBody1);

alignment(1);
write(arryFooter);
write(arryspace1);
write(arryspace1);
write(arryspace1);
write(arryspace1);

insertData(company_id,
subcompany_id,
terminal_id,
setting_control_no,
Cardno,
Balance,
transaction_no,
trace_no,
device_serial);
setting_last_transaction_no += 1;
ref_trace_no += 1;
updateTicket(String.valueOf(setting_last_transaction_no),
String.valueOf(ref_trace_no));
DBBackup();
end();
btnCheckBalance.setEnabled(true);
btnCheckBalance.setClickable(true);
Intent intent2 = new Intent(getContext(), UpdateSendingServices.class);
getActivity().startService(intent2);
} else {
//OpenNoPaper();
}
}
PrinterInterface.close();
}
});
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
totalBalance.setText("P 0.00");
btnCheckBalance.setEnabled(true);
btnCheckBalance.setClickable(true);
}
});

prettyDialog.dismiss();
}
})
.show();

即使我单击"is"漂亮的对话框按钮,我预计它也不会打印两次。

最佳答案

我认为你可以做这样的把戏

创建计数变量count=0;。单击按钮时,验证条件,以便 if(count==0) 显示对话框并使 count = 1。 (此对话框不会第二次打开)在关闭对话框时再次使 count = 0

我认为这会起作用

希望有帮助。

if(count == 0){
count = 1 ;
//showdialog process
}

就在 dismiss() 之前

  ......
count = 0;
prettyDialog.dismiss();

关于java - 如何修复 "double printing when I clicked twice on the pretty dialog button",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56334449/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com