简体   繁体   English

第二次Android不会调用onClickListener

[英]onClickListener not get called second time Android

I'm doing paypal payment for that i have to run thread in onCreate() method which initializes Button with Paypal image i'm calling one function from it which validates above fields then fires an API, if user oes wrong Toast is appeared that " ... this filed not be blanck." 我正在为此进行PayPal付款,所以我必须在onCreate()方法中运行线程,该方法用PayPal图像初始化Button,我从中调用一个函数来验证上述字段,然后触发API,如果用户出错,则会显示Toast,“ ……这不是空白。” but after this when i correct that field and again click on Btn then it does nothing. 但是在此之后,当我更正该字段并再次单击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();

I called above thread in onCreate() method of my activity. 我在活动的onCreate()方法中调用了上述线程。

code for dealResponseLogic() only deals with validation. dealResponseLogic()的代码仅处理验证。

initLibrary(); initLibrary(); It get PayPal instance make use of internet and then set some fields of that instance. 它使PayPal实例利用Internet,然后设置该实例的某些字段。

I know that i can call to that thread from that btn Listener code btn i'm looking for another way. 我知道我可以从btn侦听器代码btn调用该线程,我正在寻找另一种方法。

Please... any help will be appreciated... 请...任何帮助将不胜感激...

Try this.. 尝试这个..

Create and Start the thread inside the onClick() method of the Button .. ButtononClick()方法 创建启动 thread

Eg: 例如:

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();
    }
  });

I think it's pretty easy. 我认为这很容易。 While using paypal you have to create button using paypal, so there is one method provided by paypal to update that button ie updateButton() you just want to call that method. 使用贝宝时,必须使用贝宝创建按钮,因此贝宝提供了一种方法来更新该按钮,即,您只想调用该方法的updateButton()。 So, your button works fine everytime you click . 因此,每次单击,您的按钮都可以正常工作。

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

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