开发者

startActivityForResult is undefined for class CustomizeDialog extends Dialog

开发者 https://www.devze.com 2023-04-06 09:58 出处:网络
Iam working in android. i want to make a custom dialog in which i want to add 开发者_C百科a paypal button.

I am working in android. i want to make a custom dialog in which i want to add 开发者_C百科a paypal button.

this is the code for my program:-

public class CustomizeDialog extends Dialog implements OnClickListener {
Button close;
String TAG="CustomizeDialog";

Context customize_dialog;

CheckoutButton launchSimplePayment;

public CustomizeDialog(Context context,String title_of_song,String artist_of_song,float price_of_song) {
    super(context);

    customize_dialog=context;

    setContentView(R.layout.paypal_custom_dialog);


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


    PayPal pp = PayPal.getInstance();

    if (pp == null) {

        try {


            pp = PayPal.initWithAppID(context, "", PayPal.ENV_NONE);
        } catch (IllegalStateException e) {
            throw new RuntimeException(e);
        }
        pp.setShippingEnabled(false);
    }




launchSimplePayment = pp.getCheckoutButton(context,
            PayPal.BUTTON_118x24, CheckoutButton.TEXT_PAY);

    LinearLayout lnr = (LinearLayout) findViewById(R.id.Paypal_Custom_Dialog_View);

    launchSimplePayment.setOnClickListener( this);

    lnr.addView(launchSimplePayment);




    close.setOnClickListener(this);
}

@Override
public void onClick(View v) {

    if (v == close)

        dismiss();



    if(v==launchSimplePayment)
    {

        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,customize_dialog);

               startActivityForResult(checkoutIntent, 1); **//this line is creating error that startActivityForResult() is undefined for type CustomizeDialog** 

    }



}

are we not apply CustomizeDialog() for a activity which is extending Dialog ? (as i done in my this program) please suggest me what should i do for this ? Thank you in advance...


You can use the Activity whose theme is Dialog. This way you can achieve startActivityForResult as well as make it look like Dialog.


this is my solution:-

  1. i changed the extends Dialog to Activity.
  2. I have changed the theme of activity in menifast file to dialog as follows:- <activity android:name=".CustomizeDialog" android:label="@string/app_name" android:theme="@android:style/Theme.Dialog" />

  3. and this is the code which i have changed:-

--

package com.pericent.musicapp;

import java.math.BigDecimal;

import android.app.Activity;

import android.app.Dialog;

import android.content.Context;

import android.content.Intent;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.view.Window;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.LinearLayout;

import android.widget.TextView;

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 CustomizeDialog extends Activity implements OnClickListener {
    Button close;
    String TAG="CustomizeDialog";


 CheckoutButton launchSimplePayment;
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.paypal_custom_dialog);


    Log.v(TAG, "i am gooing to perform close");

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

        text_view_price.setText("Price : "+50);

        PayPal pp = PayPal.getInstance();
        if (pp == null) {
            try {

                pp = PayPal.initWithAppID(this, "", PayPal.ENV_NONE);

            } catch (IllegalStateException e) {

                throw new RuntimeException(e);
            }

            pp.setShippingEnabled(false);
        }




        launchSimplePayment = pp.getCheckoutButton(this,

                PayPal.BUTTON_118x24, CheckoutButton.TEXT_PAY);

 LinearLayout lnr = (LinearLayout) findViewById(R.id.Paypal_Custom_Dialog_View);

        launchSimplePayment.setOnClickListener( this);

        lnr.addView(launchSimplePayment);




        close.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        if(v==launchSimplePayment)
        {




            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);
            startActivity(checkoutIntent);//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

精彩评论

暂无评论...
验证码 换一张
取 消