繁体   English   中英

第二次Android不会调用onClickListener

[英]onClickListener not get called second time Android

我正在为此进行PayPal付款,所以我必须在onCreate()方法中运行线程,该方法用PayPal图像初始化Button,我从中调用一个函数来验证上述字段,然后触发API,如果用户出错,则会显示Toast,“ ……这不是空白。” 但是在此之后,当我更正该字段并再次单击Btn时,它什么也不做。

Thread libraryInitializationThread = new Thread() {
            public void run() {


                initLibrary();

                // The library is initialised so let's create our CheckoutButton
                // and update the UI.
                if (PayPal.getInstance().isLibraryInitialized()) {

                    runOnUiThread(new Runnable() {
                        public void run() {
                            /**
                             * Create our CheckoutButton and update the UI.
                             */
                            PayPal pp = PayPal.getInstance();

                            /**
                             * Get the CheckoutButton. There are five
                             * differentsizes. The text on the button can either
                             * be of type TEXT_PAY or TEXT_DONATE.
                             **/
                            launchChainedPaymentBtn = pp.getCheckoutButton(
                                    BuyDeal.this, PayPal.BUTTON_194x37,
                                    CheckoutButton.TEXT_PAY);

                            /**
                             * You'll need to have an OnClickListener for the
                             * CheckoutButton. For this application, MPL_Example
                             * implements OnClickListener and we have the
                             * onClick() method below.
                             **/
                            launchChainedPaymentBtn
                                    .setOnClickListener(new OnClickListener() {

                                        @Override
                                        public void onClick(View v) {

                                            // dealResponse
                                            getDealResponseLogic();

                                        }
                                    });
                            //
                            BottomBtnsLinearLayout
                                    .addView(launchChainedPaymentBtn);
                            Log.v("Btn added ", "SuccessFully...");
                            Flag = true;
                        }
                    });
                    //
                    //
                    BottomBtnsLinearLayout.addView(launchChainedPaymentBtn);
                    Log.v("Btn added ", "SuccessFully...");
                    // }
                    // });

                    Log.i("Lib. initialized", "now...");

                    /** Calling Thread to add Btn to It! **/
                    AddPayPalBtn.start();

                } else {

                    Log.i("Cannot Initialize Payment Btn",
                            "setAPyment Btn..failed due to Lib. initialization..");
                }

            }

        };
        libraryInitializationThread.start();

我在活动的onCreate()方法中调用了上述线程。

dealResponseLogic()的代码仅处理验证。

initLibrary(); 它使PayPal实例利用Internet,然后设置该实例的某些字段。

我知道我可以从btn侦听器代码btn调用该线程,我正在寻找另一种方法。

请...任何帮助将不胜感激...

尝试这个..

ButtononClick()方法 创建启动 thread

例如:

Button b = (Button)findViewById(R.id.button_Start);

b.closeButton.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {

        Thread t = new Thread(new Runnable(){

           public void run(){

               // DO YOUR LONG TIME TAKING WORK HERE.......

             }


                });

             t.start();
    }
  });

我认为这很容易。 使用贝宝时,必须使用贝宝创建按钮,因此贝宝提供了一种方法来更新该按钮,即,您只想调用该方法的updateButton()。 因此,每次单击,您的按钮都可以正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM