Android PayPal OnClickListener не работает - PullRequest
2 голосов
/ 23 марта 2012

Я пытаюсь подключить PayPal к своему приложению.В основном мое приложение будет иметь одну кнопку сканирования и одну кнопку PayPal на экране.Кнопка Scan вызывает библиотеку ZXing и сканирует штрих-коды.Тем не менее, я все еще не могу соединиться с кнопкой PayPal, потому что OnClickListener и getApplicationContext() не работает.Я прочитал документацию PayPal, StackOverflow и до сих пор не могу работать.Мне интересно, что не так с моим кодом?Любые предложения, пожалуйста? Спасибо за вашу помощь:)

package thet.mon.aye;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ListView;

import android.widget.RelativeLayout;
import android.widget.SimpleCursorAdapter;
import com.paypal.android.MEP.CheckoutButton;
import com.paypal.android.MEP.PayPal; 
import com.paypal.android.MEP.PayPalReceiverDetails;
import com.paypal.android.MEP.PayPalPayment;
import android.content.Context;

public class DevilscanActivity extends ListActivity implements onClickListener {
    /** Called when the activity is first created. */

private static final int ACTIVITY_CREATE=0;
private BarcodeDBAdapter mDbHelper;
private Cursor mNotesCursor;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mDbHelper = new BarcodeDBAdapter(this);
    mDbHelper.open();
    fillData();
    PayPal ppObj = PayPal.getInstance();

       final Button scanButton = (Button) findViewById(R.id.button);
    scanButton.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {  

            Intent intent1 = new Intent("com.google.zxing.client.android.SCAN");
            intent1.putExtra("SCAN_MODE", "1D_CODE_MODE");
            startActivityForResult(intent1, 0);

        }

    });

CheckoutButton launchPayPalButton = ppObj.getCheckoutButton(this, PayPal.BUTTON_278x43, CheckoutButton.TEXT_PAY);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    params.bottomMargin = 10;
launchPayPalButton.setLayoutParams(params);
    launchPayPalButton.setOnClickListener((OnClickListener) this);
((RelativeLayout)findViewById(R.id.RelativeLayout01)).addView(launchPayPalButton);


}
static public PayPal initWithAppID(Context context, String appID, int server)
{    
        PayPal ppObj;
    if (ppObj == null) {
        try {

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

     }



private void fillData() {
    // Get all of the rows from the database and create the item list
    mNotesCursor = mDbHelper.fetchAllNotes();
    startManagingCursor(mNotesCursor);

    // Create an array to specify the fields we want to display in the list (only TITLE)
    String[] from = new String[]{BarcodeDBAdapter.KEY_BARCODE_TYPE};

    // and an array of the fields we want to bind those fields to (in this case just text1)
    int[] to = new int[]{R.id.text1};

    // Now create a simple cursor adapter and set it to display
    SimpleCursorAdapter notes = 
        new SimpleCursorAdapter(this, R.layout.barcode_row, mNotesCursor, from, to);
    setListAdapter(notes);
}


public void onActivityResult(int requestCode, int resultCode, Intent intent1) {
    //intent1 = new Intent("com.google.zxing.client.android.SCAN");
   // intent1.putExtra("SCAN_MODE", "QR_CODE_MODE");
   // startActivityForResult(intent1, 0);
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            String contents = intent1.getStringExtra("SCAN_RESULT");
            String format = intent1.getStringExtra("SCAN_RESULT_FORMAT");
            mDbHelper.createNote(contents, format);

        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
        }
    }

}

}

...