请阅读以下代码中的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.
}
}
这可能吗? 是否有关键字从对象内的函数访问主类对象?
答案 0 :(得分:6)
是的,您应该使用Field
从匿名类实例中访问;
实例。