Question: finding a selected item from CrimeListFragment


The text used the following code to get the item.


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


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.


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.


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