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?

Neuron
  • 5,141
  • 5
  • 38
  • 59
SadeepDarshana
  • 1,057
  • 18
  • 34

1 Answers1

6

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

Eran
  • 387,369
  • 54
  • 702
  • 768