I have a main Activity class that has a button to which I assign an OnClickListener:
public class MyMainClass extends Activity {
protected void initWidgets() {
btAddProfile = (Button) findViewById(R.id.btAddProfile);
btAddProfile.setOnClickListener(onAddProfileClick);
}
protected View.OnClickListener onAddProfileClick = new View.OnClickListener() {
public void onClick(View view) {
addHotspot();
}
};
protected void addHotspot(){
//doStuff
}
}
The onAddProfileClick instance is a child of MyMainClass, and yet it's able to call MyMainClass's addHotspot() function without referencing MyMainClass. How is that possible?
This is not their parent, but their enclosing class, and they may do that as they are associated with the enclosing object and in its scope. (there is an implicit call to MyMainClass.this.addHotspot()
when you write addHotspot()
)