5

Please read the 2 comments in the following code.

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

Is this possible? Is there a keyword to access the main class object from a function inside the object?

SadeepDarshana
  • 989
  • 16
  • 32

1 Answers1

6

Yes, you should use Field.this to access the Field instance from within the anonymous class instance.

Eran
  • 374,785
  • 51
  • 663
  • 734