Not sure how to phrase the question to be technically correct, but suppose I have an object (outer) that has a method which takes another object (inner) as a parameter - how can I refer to outer from within inner?
To clarify what I mean, here's an example using an Android EditText and an implementation of TextWatcher:
EditText myEditText = getEditText();
myEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
// How can I refer to myEditText here in a more generic way than
// using myEditText directly?
}
});
In this example I could of course just use myEditText inside the TextWatcher implementation. But what I want to know is if there is a more generic way to get to the "outer" object from the "inner" in this case?
I know that one can use MyClass.this when dealing with anonymous inner classes, but that doesn't work in this case.