请阅读以下代码中的2条注释。
public class Field extends LinearLayout {
public void init() {
setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// I want to access the main object 'Field' here(not the class, the object)
}
});
// to be clear the object referred as 'this' from HERE should be accessed from where the above comment is.
}
}
这可能吗?是否有关键字可以从对象内部的函数访问主类对象?
是的,您应该用来从匿名类实例中Field.this
访问Field
实例。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句