Question: finding a selected item from CrimeListFragment


#1

The text used the following code to get the item.

(Crime)getListAdapter()).getItem(position)

Is there any particular reason? mCrimes.get(position) worked too. Which one should we use?


#2

Either is fine. We prefer the version that fetches the item from the adapter because the position is actually coming from the adapter, not the list object. That makes it easier to change that adapter’s relationship to its underlying dataset later if we need to.


#3

So, just to confirm, are you saying that if you wanted to swap out the ArrayList of Crimes for an ArrayList of GoodDeeds, that this would make it easier? I can see that here I think. However, if you have a further comment or explanation that would be much appreciated.


#4

A better example would be if you wanted the adapter to backed by a cursor instead of an ArrayList.