从EditText获取值时出错?

时间:2014-05-23 17:02:40

标签: android paypal android-edittext

我在我的App中集成了paypal。我需要从Edittext获取金额。 我尝试使用String类型,但PayPalPayment方法是在BigDecimal中。 抛出错误

The Constructor BigDecimal(BigDecimal) is undefined

所以请纠正我......

protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.donate);


    Intent intent = new Intent(this, PayPalService.class);

    intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);

    startService(intent);
}

public void onBuyPressed(View pressed)
{       
EditText amount = (EditText) findViewById(R.id.amtdon);
    BigDecimal amt = (BigDecimal) amount.getText();
    PayPalPayment payment = new PayPalPayment(new BigDecimal(amt), "USD", "Donate Remote IT ", PayPalPayment.PAYMENT_INTENT_SALE);

    Intent intent = new Intent(this, PaymentActivity.class);

    intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);

    startActivityForResult(intent, 0);
}

2 个答案:

答案 0 :(得分:3)

也许你需要更换

BigDecimal amt = (BigDecimal) amount.getText();

BigDecimal amt = new BigDecimal(amount.getText().toString());

<强>更新

替换

EditText amount = (EditText) findViewById(R.id.amtdon);
BigDecimal amt = (BigDecimal) amount.getText();
PayPalPayment payment = new PayPalPayment(new BigDecimal(amt), "USD", "Donate Remote IT ", PayPalPayment.PAYMENT_INTENT_SALE);

EditText amount = (EditText) findViewById(R.id.amtdon);
BigDecimal amt = new BigDecimal(amount.getText().toString());
PayPalPayment payment = new PayPalPayment(atm, "USD", "Donate Remote IT ", PayPalPayment.PAYMENT_INTENT_SALE);

答案 1 :(得分:1)

尝试这样做

BigDecimal amt = new BigDecimal(amount.getText().toString);