Manipulating with array adapter or with the underlaying data?
<p>In the book <em>The Busy Coders Guide to Android Development</em> from CommonsWare, there is a chapter explaining how to work with the context menus.</p>

<p>In one example in that chapter, the context menu offers option for removing item from a list view that is generated from an <code>ArrayList&lt;String&gt;</code> object named <code>words</code>.</p>

<p>In the example the <code>onContextItemSelected</code> method is implemented like this:</p>

<pre><code>public boolean onContextItemSelected(MenuItem item) {
  AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
  ArrayAdapter&lt;String&gt; adapter=(ArrayAdapter&lt;String&gt;)getListAdapter();
  switch (item.getItemId()) {   
  case R.id.remove:
    adapter.remove(words.get(info.position));
    return true;
  default:
  ...
}
</code></pre>

<p>The line where <code>adapter.remove(...)</code> is called seems strange to me because of following fact:</p>

<p>Let's say the <code>words</code> object contains following items (in that order)</p>

<ul>
<li>alfa</li>
<li>beta</li>
<li>gama</li>
<li>alfa</li>
</ul>

<p>Now, when user loads the context menu upon the <em>2nd</em> alfa and selects the option for removing it, the mentioned line actually removes the <em>1st</em> alfa. And that seems wrong to me.</p>

<p>Instead, I would do something like this:</p>

<pre><code>...
words.remove(info.position);
adapter.notifyDataSetChanged();
...
</code></pre>

<p>I'm not that good in Java and Android programming, so I would like to hear your opinion to this, because I want to be sure I understand well how adapters should be used.</p>
