Inner and anonymous classes
Before we go ahead to the next chapter and build apps with loads of different widgets that will put into practice and reinforce everything we have learned in this chapter, we will have a very brief introduction to Anonymous and Inner classes.
When we implemented our basic classes demo app in Chapter 10, Object-Oriented Programming, we declared and implemented the class in a separate file to our MainActivity
class. That file had to have the same name as the class. This is the way to create a regular class.
We can also declare and implement classes within a class. Other than how we do this, the only question remaining, of course, is why would we do this?
When we implement an inner class, the inner class can access the member variables of the enclosing class and the enclosing class can access the members of the inner class.
This often makes the structure of our code more straightforward. So inner classes are sometimes the way to go.
In addition...