Question on creating an adapter subclass (Listing 9.18)


Under listing 9.18 you state "The call to the superclass constructor is required to properly hook up your dataset of Crimes. I guess I’m still having some Java issues about getActivity and constructors. However, is super meant to use the getActivity from the CrimeListFragment class?

If so, how is this a call to the “superclass constructor?” Is super() causing a new CrimeListFragment to be instantiated?

Also, the superclass call uses “crimes” somehow, but how? I mean where can I find the method or whatever that uses crimes to do this hook up?

Sorry, all these OOP layers are confusing me and I’ve been stuck trying to follow the yellow brick road on this one for a couple of days now. I’m probably making this more complicated than it is.


I think I found the answer after posing my questions. Basically, the adapter object is created using "new ArrayAdapter(getActivity…) " which is a call to the ArrayAdapter constructor (initial use on pg. 181.) Then, you create a subclass to allow defining your own layout by passing in crimes (your “hook up” term on page 187) but no “predefined” layout, and then finally overriding the getView method (listing 9.19.) that defines your custom layout. Am I correct?

You explained things very well, but I had life interfere between doing the initial ArrayAdapter setup on page 181 and then altering it on page 187-188. I didn’t delete this just in case another rusty Java newbie has the same problem.


You are correct! Glad to hear you cleared up your confusion.