如何在我的自定义对话框中添加我的付款按钮?

时间:2011-09-21 09:46:27

标签: android

我在android工作。我想在我的自定义按钮中添加paypal按钮。我创建了自定义对话框和贝宝按钮。但这两者都具有不同的活力。请建议我该怎么做。

这是我创建自定义对话框的类。: -

package com.pericent.musicapp;

import android.app.Dialog;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class CustomizeDialog extends Dialog implements OnClickListener {
    Button close;
    String TAG="CustomizeDialog";
    TextView text_view_artist_name;
    TextView text_view_song_title;
    TextView text_view_price;

    public CustomizeDialog(Context context,String title_of_song,String artist_of_song,float price_of_song){
        super(context);
        /** It will hide the title */
        requestWindowFeature(Window.FEATURE_NO_TITLE);      
        setContentView(R.layout.paypal_custom_dialog);
        Log.v(TAG, "i am gooing to perform close");

        text_view_song_title=(TextView)findViewById(R.id.Paypal_TextView_songName);

        text_view_artist_name=(TextView)findViewById(R.id.Paypal_TextView_byArtist);

        text_view_price=(TextView)findViewById(R.id.Paypal_TextView_songPrice);

        text_view_song_title.setText("Title : "+title_of_song);

        text_view_artist_name.setText("Artist : "+artist_of_song);

        close = (Button) findViewById(R.id.paypal_close);

        text_view_price.setText("Price : "+price_of_song);
        close.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Log.v(TAG, "i am closing tag");
        if (v == close)
            dismiss();
    }

}

这是由上面的代码创建的自定义对话框: -

enter image description here

现在我想在此自定义对话框中添加我的paypal按钮。请建议我该怎么做。这是我创建paypal按钮的代码: -

package com.pericent;
import java.math.BigDecimal;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;   
import com.paypal.android.MEP.CheckoutButton;
import com.paypal.android.MEP.PayPal;
import com.paypal.android.MEP.PayPalActivity;
import com.paypal.android.MEP.PayPalPayment;
import com.paypal.android.MEP.PayPalAdvancedPayment;
import com.paypal.android.MEP.PayPalInvoiceData;
import com.paypal.android.MEP.PayPalInvoiceItem;
import com.paypal.android.MEP.PayPalReceiverDetails;

public class MypaypalActivity extends Activity implements OnClickListener{   

    @Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LinearLayout mLinLay= new LinearLayout(this);
        setContentView(R.layout.main);
        PayPal pp = PayPal.initWithAppID(this, "APP-80W284485P519543T", PayPal.ENV_SANDBOX);

        LinearLayout layoutSimplePayment = new LinearLayout(this);
        layoutSimplePayment.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        layoutSimplePayment.setOrientation(LinearLayout.VERTICAL);
        CheckoutButton launchSimplePayment = pp.getCheckoutButton(this, PayPal.BUTTON_118x24, CheckoutButton.TEXT_PAY);

        launchSimplePayment.setOnClickListener( this);   
        layoutSimplePayment.addView(launchSimplePayment);
        mLinLay.addView(layoutSimplePayment);

        setContentView(mLinLay);
    }

    public void onClick(View v) {
        PayPalPayment payment = new PayPalPayment();
        payment.setSubtotal(new BigDecimal("2.25"));
        payment.setCurrencyType("USD");
        payment.setRecipient("kuntal_1316186174_biz@gmail.com");
        payment.setPaymentType(PayPal.PAYMENT_TYPE_GOODS);

        Intent checkoutIntent = PayPal.getInstance().checkout(payment, this);
        startActivityForResult(checkoutIntent, 1);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (resultCode) {
        case Activity.RESULT_OK:
            break;

        case Activity.RESULT_CANCELED:
            break;

        case PayPalActivity.RESULT_FAILURE:
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}

提前谢谢你......

0 个答案:

没有答案