[英]how to reference a higher class within an anonymous 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
}
}
}
你可以试试:
ContextNotionLevel ctnl=new ContextNotionLevel(Home.this);
您可以使用Home.this
来引用Home对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.