[英]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調用該線程,我正在尋找另一種方法。
請...任何幫助將不勝感激...
嘗試這個..
在Button
的onClick()
方法內 創建並啟動 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.