简体   繁体   中英

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." but after this when i correct that field and again click on Btn then it does nothing.

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.

code for dealResponseLogic() only deals with validation.

initLibrary(); It get PayPal instance make use of internet and then set some fields of that instance.

I know that i can call to that thread from that btn Listener code btn i'm looking for another way.

Please... any help will be appreciated...

Try this..

Create and Start the thread inside the onClick() method of the Button ..

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. So, your button works fine everytime you click .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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