如何在匿名类中引用更高级的类

Pen*_*m10 3 java android anonymous-inner-class class inner-classes

我有这个代码:

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
              }
    }
}
Run Code Online (Sandbox Code Playgroud)

cch*_*son 5

你可以试试:

 ContextNotionLevel ctnl=new ContextNotionLevel(Home.this);
Run Code Online (Sandbox Code Playgroud)