Getting all of the items from an ArrayAdapter
<p>I have a <code>ListFragment</code> backed by an <code>ArrayAdapter</code> that gets populated by a <code>Loader</code>. When the user clicks on one of the items, I want to pass a reference to the selected item, as well as the rest of the list items to another fragment. My question is how should I get all of the items from the adapter? Here are the possibilities that I see:</p>

<p><strong>1. Keep a reference to the backing <code>List</code></strong></p>

<p>Create the adapter like so:</p>

<pre><code>List&lt;DomainObject&gt; items = new ArrayList&lt;DomainObject&gt;();
listAdapter = new ArrayAdapter&lt;DomainObject&gt;(getActivity(), R.layout.mine, items);
</code></pre>

<p>and then simply pass <code>items</code> or a copy of it to the next activity.</p>

<p>The downside I see of this is that I'm relying on the undocumented fact that the same list that I pass to the constructor contains the items later on.</p>

<p><strong>2. Iterate through the adapter</strong></p>

<p>When an item is clicked, iterate through the adapter and build up the list. This seems like an unnecessary amount of work. The items are contained in a <code>List</code> in the adapter and I'm manually copying each item to a new list.</p>

<p><strong>3. Keep a separate list of items when adding to adapter</strong></p>

<p>Before adding an item to the adapter, add it to a separate list that I maintain in the fragment. This is also wasteful as the list of items is copied in the <code>ArrayAdapter</code> and the fragment.</p>
