我正在使用PayPal的應用程序。我需要使用MPL,而不是SDK,因爲我的應用需要能夠實施第三方支付。我已經關注了各種教程並創建了下面的代碼。我沒有收到任何編譯器錯誤,也沒有登錄錯誤,但是當我運行它並點擊「Pay with PayPal」按鈕時,沒有任何反應。相反,當我點擊按鈕或屏幕上的任何位置時,我會得到ViewPostImeInputStage ACTION_DOWN
。onClick沒有做任何事情...「ViewPostImeInputStage ACTION_DOWN」
我不知道爲什麼。請幫忙!
public class MainActivity extends Activity implements View.OnClickListener {
private CheckoutButton launchPayPalButton;
final static public int PAYPAL_BUTTON_ID = 10001;
private double _theSubtotal;
private double _taxAmount;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initLibrary();
showPayPalButton();
}
private void showPayPalButton() {
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
ViewGroup.LayoutParams linearLayoutParam = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
setContentView(linearLayout, linearLayoutParam);
LayoutParams lpView = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// Generate the PayPal checkout button and save it for later use
PayPal pp = PayPal.getInstance();
launchPayPalButton = pp.getCheckoutButton(this, PayPal.BUTTON_194x37, CheckoutButton.TEXT_PAY);
// The OnClick listener for the checkout button
launchPayPalButton.setOnClickListener(this);
// Add the listener to the layout
launchPayPalButton.setLayoutParams(lpView);
launchPayPalButton.setId(PAYPAL_BUTTON_ID);
linearLayout.addView(launchPayPalButton);
}
public void PayPalButtonClick(View arg0) {
PayPalPayment newPayment = new PayPalPayment();
newPayment.setSubtotal(new BigDecimal(_theSubtotal));
newPayment.setCurrencyType("USD");
newPayment.setRecipient("[email protected]");
newPayment.setMerchantName("My Company");
Intent paypalIntent = PayPal.getInstance().checkout(newPayment, this);
this.startActivityForResult(paypalIntent, 2);
}
public void initLibrary() {
PayPal pp = PayPal.getInstance();
if (pp == null) { // Test to see if the library is already initialized
// This main initialization call takes your Context, AppID, and target server
pp = PayPal.initWithAppID(this, "APP-80W284485P519543T", PayPal.ENV_NONE);
// Required settings:
// Set the language for the library
pp.setLanguage("en_US");
// Some Optional settings:
// Sets who pays any transaction fees. Possible values are:
// FEEPAYER_SENDER, FEEPAYER_PRIMARYRECEIVER, FEEPAYER_EACHRECEIVER, and FEEPAYER_SECONDARYONLY
pp.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER);
// true = transaction requires shipping
pp.setShippingEnabled(false);
}
}
@Override
public void onClick(View arg0){
PayPalButtonClick(arg0);
}
}
謝謝...我有問題,因爲我從來沒有設置意見程序;只使用了.xml文件。我應該使用'setContentView(R.layout.activity_main);'?如何解決onClickListener問題? –
看起來你不是從xml構建你的視圖,所以在你的showPaypalButton()的末尾做setContentView(linearLayout)應該可以工作。 – monopandora
我把它改爲: 'launchPayPalButton.setOnClickListener(新View.OnClickListener(){ @覆蓋 公共無效的onClick(查看爲arg0){ payPalButtonClick(爲arg0);} });' 但問題遺蹟。另外,我在showPaypalButton方法中設置了contentView。 –