onClick没有做任何事情......" ViewPostImeInputStage ACTION_DOWN"

时间:2016-03-11 02:46:36

标签: java android paypal

我正在开发一款使用PayPal的应用。我需要使用MPL,而不是SDK,因为我的应用程序需要能够实现第三方付款。我已经按照各种教程编写了下面的代码。我没有得到任何编译器错误,也没有日志cat错误,但是当我运行它并点击" Pay with PayPal"按钮,没有任何反应。相反,当我点击按钮或屏幕上的任何地方时,我得到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("my@email.com");
    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);
}

}

2 个答案:

答案 0 :(得分:0)

可能是因为你没有在super.oncreate()之后设置内容视图,并且因为你将你的活动注册为点击监听器,它会响应屏幕上任何地方的点击而不仅仅是按钮。

修改

在按钮上添加一个点击监听器,如下所示

paypalButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View arg0) {  PayPalButtonClick(arg0); }
});

并从您的活动中删除OnClickListener的实现

答案 1 :(得分:0)

ViewPostImeInputStage ACTION_DOWN基本上是一种情况,当您的布局被拒绝并且您无法再单击任何可点击的项目时。此解决方案很简单,只需用父项包装您的布局内容。

代表:

if you have the xml with format as:
<LinearLayout <---root layout
 ..... contents here
</LinearLayout> <-- root layout end

change to 

<FrameLayout <---root layout
   <LinearLayout <-- parent wrap start
   ...
<!-- your content -->
   </LinearLayout> <-- parent wrap end
</FrameLayout> <-- root layout end

有关详细信息,您可以考虑阅读this