Subclass versus override


Hi there,

Thanks for the awesome book! Small question: in listing 9.18, why can’t you just override ArrayAdapter to customize it instead of creating a new subclass?



I’m not sure about how to answer your question, because I’m not sure what you’re asking. The only way to override methods on ArrayAdapter is to create a subclass - whether that’s as a standalone class, an inner class, or an anonymous inner class (like how we create OnClickListeners in the book). Any of those three methods will work the same, so if you want to use e.g. an anonymous inner class, it will work fine. We prefer a named inner class in this case due to the size of the implementation. Including it within onCreate() would make that method hard to read on the page.