2

这个正在破坏我的大脑,当您进入活动时,您可以单击贝宝按钮,然后您就可以进入贝宝活动。如果您取消贝宝活动,您将被带回原来的活动。从这里,如果您再次单击该按钮,则不会发生任何事情。我尝试在 OnClick 方法中向控制台打印一条基本消息,但它甚至没有显示,它似乎没有注册点击。我假设问题与布局 xml 文件或清单文件无关。我会发布一张图片,但我不能,因为我是新手,你只需要知道它是一个带有 paypal 按钮的结帐屏幕。

在此先感谢,休。

package com.cit.datastructuretesting;

import java.math.BigDecimal;
import java.text.DecimalFormat;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.paypal.android.MEP.CheckoutButton;
import com.paypal.android.MEP.PayPal;
import com.paypal.android.MEP.PayPalPayment;

public class StoreItemInterface extends Activity implements OnClickListener, OnKeyListener
{           
Double subtotal, shipping, total;
EditText etItemQuantity;
TextView tvItemSubtotal, tvItemTotal;
DecimalFormat decFormat = new DecimalFormat("#.##");
PayPal ppObj;
CheckoutButton launchPayPalButton;



@Override
protected void onCreate(Bundle savedInstanceState) 
{       
    super.onCreate(savedInstanceState);     

    setContentView(R.layout.storeiteminterface);

    ImageView ivItemImage = (ImageView) findViewById(R.id.ivItemImage2);
    TextView tvItemTitle = (TextView) findViewById(R.id.tvItemTitle2);
    TextView tvItemDescription = (TextView) findViewById(R.id.tvItemDescription2);
    etItemQuantity = (EditText) findViewById(R.id.etItemQuantity);
    tvItemSubtotal = (TextView) findViewById(R.id.tvItemSubtotal);
    TextView tvItemShipping = (TextView) findViewById(R.id.tvItemShipping);
    tvItemTotal = (TextView) findViewById(R.id.tvItemTotal);    

    subtotal = Main.appData.getStore().getStoreCatagory(StoreInterface.currentCatagory).getStoreItem(StoreItemsInterface.currentItem).getPrice() * Integer.parseInt(etItemQuantity.getText().toString());
    shipping = Main.appData.getStore().getStoreCatagory(StoreInterface.currentCatagory).getStoreItem(StoreItemsInterface.currentItem).getShippingPrice();
    total = subtotal + shipping;

    ivItemImage.setImageBitmap(Main.appData.getStore().getStoreCatagory(StoreInterface.currentCatagory).getStoreItem(StoreItemsInterface.currentItem).getImageBitmap());            
    tvItemTitle.setText(Main.appData.getStore().getStoreCatagory(StoreInterface.currentCatagory).getStoreItem(StoreItemsInterface.currentItem).getTitle());
    tvItemDescription.setText(Main.appData.getStore().getStoreCatagory(StoreInterface.currentCatagory).getStoreItem(StoreItemsInterface.currentItem).getDescription());
    tvItemSubtotal.setText("€" + decFormat.format(subtotal));       
    tvItemShipping.setText("€" + decFormat.format(shipping));       
    tvItemTotal.setText("€" + decFormat.format(total)); 

    etItemQuantity.setOnKeyListener(this);

    //setup paypal stuff
    ppObj = PayPal.initWithAppID(this.getBaseContext(), "APP-80W284485P519543T", PayPal.ENV_SANDBOX);

    launchPayPalButton = ppObj.getCheckoutButton(this, PayPal.BUTTON_278x43, CheckoutButton.TEXT_PAY);

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    params.bottomMargin = 10;

    launchPayPalButton.setLayoutParams(params);        

    ((RelativeLayout)findViewById(R.id.paypalLayout)).addView(launchPayPalButton); 

    launchPayPalButton.setOnClickListener(this);
}

@Override
public void onClick(View arg0) 
{       
    if(arg0.getId() == launchPayPalButton.getId())
    {
        System.out.println("TEST");

        if(!tvItemTotal.getText().toString().equals("---"))
        {
            PayPalPayment newPayment = new PayPalPayment();
            newPayment.setSubtotal(BigDecimal.valueOf(total));
            newPayment.setCurrencyType("EUR");
            newPayment.setRecipient("Cape_1328492032_biz@mycit.ie");
            newPayment.setMerchantName("Cape Clear App");

            Intent paypalIntent = PayPal.getInstance().checkout(newPayment, StoreItemInterface.this);
            StoreItemInterface.this.startActivityForResult(paypalIntent, 1);
        }
        else
        {
            Toast.makeText(StoreItemInterface.this, "Invalid Quantity!", Toast.LENGTH_SHORT).show();
        }
    }       
}

@Override
public boolean onKey(View arg0, int arg1, KeyEvent arg2) 
{       
    if(etItemQuantity.getText().toString() != null && !etItemQuantity.getText().toString().trim().equals("") && !etItemQuantity.getText().toString().trim().equals("0"))
    {
        subtotal = Main.appData.getStore().getStoreCatagory(StoreInterface.currentCatagory).getStoreItem(StoreItemsInterface.currentItem).getPrice() * Integer.parseInt(etItemQuantity.getText().toString());
        total = subtotal + shipping;

        tvItemSubtotal.setText("€" + subtotal);         
        tvItemTotal.setText("€" + decFormat.format(total));
    }
    else
    {
        tvItemSubtotal.setText("---");          
        tvItemTotal.setText("---");         
    }

    return false;
}   

}

4

2 回答 2

5

在 onClick() 执行的操作之后尝试 launchPayPalButton.updateButton()

https://www.x.com/developers/paypal/forums/paypal-mobile-xspace/android-interrupting-paypal-onclick-event#answer-203333

于 2012-03-18T01:13:34.050 回答
3

如果您仍在寻找答案,我有一个

如果您查看getCheckoutButton方法,它将Context作为参数,因此当Activity例如说当您启动另一个时发生的 Paused 时Activity,该实例CheckoutButton会以某种方式丢失。

我修复是通过updateButton在活动的 onResume 中使用方法

@Override
protected void onResume() {
    /**
     * The CheckoutButton has to be updated each time the Activity is
     * resumed, otherwise the onClickListener of CheckoutButton will not work
     **/
    if (mCheckOutBtn != null && (mCheckOutBtn instanceof CheckoutButton))
        mCheckOutBtn.updateButton();
    super.onResume();
}

考虑到您已初始化库PayPalCheckoutButtononCreate.Activity

于 2012-10-10T09:47:24.140 回答