Let’s say we have some Foo class that contains
public void setOnSomethingListener(OnSomethingListener listener);
We register it with:
Foo foo = new Foo();
foo.setOnSomethingListener(new OnSomethingListener(){
public void onSomething(String data) {
// ...
}
});
Is it possible to access from onSomething method parental object that has registered mentioned listener without accessing defined foo value ?
I ask about it because I would like to assign this listener to some parameter and register it in the few objects.
Yes.
What you are doing here is defining an anonymous inner class. You can access attributes and methods of the containing class by doing.