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

时间:2010-02-07 21:58:01

标签: java android class inner-classes anonymous-inner-class

我有这段代码:

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
              }
    }
}

2 个答案:

答案 0 :(得分:5)

您可以尝试:

 ContextNotionLevel ctnl=new ContextNotionLevel(Home.this);

答案 1 :(得分:3)

您可以使用Home.this来引用Home对象。