-4

Possible Duplicate:
Accessing the containing class of an inner class in Java

I know this has certainly been answered before, but I have been working on this for two straight nights and I either don't understand or I have messed something up badly. I am trying to call a method with a button. My method is only going to copy and paste so it's not opening another activity.

package com.example.copypastetest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class PDFtester extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pdftester);
            Button b1 = (Button) findViewById(R.id.button2);
            b1.setOnClickListener(new OnClickListener(){;

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            //public void work (View view){
    this is my issue??-->Intent intent = new Intent(this, copyAsset.class);
            startActivity(intent);}         
        }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_pdftester, menu);
        return true;}
    };

thank you for looking, I admit I am a total hack. The only reason I made it this far is this website, first question, im sure of many but hopefully someone can help. I am not trying to be a vampire but I really am looking for the correct answer here if there is a page i can read to understand what i did wrong i am all ears.

Thanks.

Community
  • 1
  • 1
  • 3
    This has **definitely** been answered already. Just use `PDFtester.this` instead of `this`. – A--C Jan 24 '13 at 03:33
  • 1
    I don't really understand what you want... If you want to copy/paste, then why are you creating an Intent... and what is this class: copyAsset? – Adam Toth Jan 24 '13 at 03:40
  • why is it PDFtester? I honestly have 6+ hours in this....... – user2002272 Jan 24 '13 at 03:41
  • copy a folder to the sdcard, use the pdf in it, then wipe the folder when done. – user2002272 Jan 24 '13 at 03:42
  • @user2002272 The compiler must have given you an error, like this [SO](http://stackoverflow.com/questions/4487911/the-constructor-intentnew-view-onclicklistener-classdrinkstwitter-is-un) question. – A--C Jan 24 '13 at 03:49
  • Firstly you should be clear what exactly you want to do, you are messing up the questions. – Hulk Jan 24 '13 at 04:21

2 Answers2

1

Use this code:

    @Override
    public void onClick(View view) {
        // TODO Auto-generated method stub
        //public void work (View view){
        Intent intent = new Intent(PDFtester.this, copyAsset.class);
        startActivity(intent);}         
    }

Note :- Interfaces like OnClickListener,OnTouchListener etc don't use this for getting Context try to use YourActivity.this or getApplicationContext()

edwin
  • 7,985
  • 10
  • 51
  • 82
  • First of all thank you to edwin. When i created the new class I had put it in the default package, hence all of my "RED" I moved it from the "Default Package" to com.example.mypackagename. and what do you know. thanks again. – user2002272 Jan 25 '13 at 01:38
  • take care with Manifest.xml while adding activities to it – edwin Jan 25 '13 at 05:30
0
b1.setOnClickListener(new OnClickListener(){;

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        //public void work (View view){
this is my issue??-->Intent intent = new Intent(PDFtester.this, copyAsset.class);
        startActivity(intent);}         
    }

 // define the scope as PDFtester.this
user123321
  • 12,593
  • 11
  • 52
  • 63