Pentium10
Pentium10

Reputation: 207912

how to reference a higher class within an anonymous class

I have this code:

public class Home extends Activity{

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            //...
            //at some point I have
            s.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){

              @Override
              public void onProgressChanged(SeekBar seekBar, int progress,
                      boolean fromUser) {

                  ContextNotionLevel ctnl=new ContextNotionLevel(this);
// <-- how can I reference Home class here to replace **this**, which as it is points to OnSeekBarChangeListener
              }
    }
}

Upvotes: 3

Views: 350

Answers (2)

ccheneson
ccheneson

Reputation: 49410

You can try:

 ContextNotionLevel ctnl=new ContextNotionLevel(Home.this);

Upvotes: 5

sepp2k
sepp2k

Reputation: 370172

You can use Home.this to refer to the Home object.

Upvotes: 3

Related Questions