调用两次“for”循环以打印两张收据

时间:2016-12-13 11:26:55

标签: android printing bluetooth

我的应用程序中集成了蓝牙打印机,如果我进行了一些交易,我可以将收据打印给客户。我有一种方法来处理收据的打印。目前,我只能打印一张收据,但我想打印收据两次。

我应该运行for循环两次,以便打印收据的方法执行两次。

private void printReceipt(final Transaction transaction) {
    showProgressPopup(getString(R.string.printing_dialog_message));
    Runnable printThread = new Runnable() {

        @Override
        public void run() {
            final BitSet resultBit = new BitSet(1);
            try {
                final ReceiptMetadata receiptMetadata =
                        AirFiUtils.getPaymentDeviceReceiptMetaData(getAirlineProfile(),
                                AirFiUtils.getMerchantAccount(getAirFiActivity()));
                if (null != receiptMetadata) {
                    PrinterManager.printReceipt(PrinterType.valueOf(receiptMetadata.getPrinter().get(0)),
                            ReceiptType.CASH, receiptMetadata, transaction, getActivity().getApplicationContext(),
                            transaction.isSignatureCard());

                    resultBit.set(0, true);
                }
            } catch (Exception e) {
                LOG.error("Error in printing ", e);
                resultBit.set(0, false);
            }
        }
    };
    new Thread(printThread).start();
}

1 个答案:

答案 0 :(得分:0)

在if语句中使用for循环,例如

if(your_condition){
for(int i=0;i<2;i++){
//your desired code to print receipt
}}

或两次调用您的特定功能,需要通过申请循环

打印收据