Android Paypal 启动按钮 OnClick 在 Activity 生命周期内只执行一次

标签 android paypal onclick onclicklistener

这个正在毁掉我的大脑,当你进入 Activity 时,你可以点击 paypal 按钮,然后你就可以进入 paypal Activity 了。如果您取消 Paypal Activity ,您将回到原来的 Activity 。从这里,如果您再次单击该按钮,则不会发生任何事情。我尝试在 OnClick 方法中打印一条基本消息到控制台,但它甚至没有显示,它似乎没有记录点击。我假设问题与布局 xml 文件或 list 文件无关。我会张贴图片,但我不能,因为我是新手,您只需要知道它是一个带有 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;
}   

最佳答案

关于Android Paypal 启动按钮 OnClick 在 Activity 生命周期内只执行一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9691578/

相关文章:

Android TextView 将文本左右对齐

android - opensense sdk 笔示例 - HtcPaintingView ClassNotFoundException

android - 正确地将节点从最新到最旧排序

android - 如何从其他 View 的事件访问 View ( View 在布局层次结构中的不同分支中)?

javascript - 使用Jquery绑定(bind)函数(带参数)到点击事件

android - 为 Android ListView 中的行分配 ID

php - Paypal IPN 数据未进入数据库

ruby - Paypal express ActiveMerchant 网关不工作

paypal - 使用 GET 转发到 Paypal

javascript - 由于 Google Analytics 跨域 javascript 链接跟踪,目标 ="_blank"未打开新页面