我调试我的应用程序然后我尝试在漂亮的对话框按钮上快速单击两次并打印两次我希望即使我单击两次它也不会打印两次。我尝试了错误处理程序代码,但没有用。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)); 我希望即使我单击“是”漂亮的对话框按钮也不会打印两次。
1 回答
慕桂英3389331
TA贡献2036条经验 获得超8个赞
我想你可以做这样的把戏
创建一个计数变量 count=0;。在单击按钮时,验证条件以if(count==0)显示对话框并制作count = 1. (此对话框将不会第二次打开)同时count = 0再次关闭对话框。
我认为这会奏效
希望能帮助到你。
if(count == 0){
count = 1 ;
//showdialog process
}
就在之前dismiss()
......
count = 0;
prettyDialog.dismiss();
添加回答
举报
0/150
提交
取消