Deleting row from database using _id column in context menu from ListView
<p>I have a listview which is populated by a <code>SimpleCursorAdapter</code> that is binding data to the view from a cursor from a sqlite database. I would like to have a context menu option to delete the a list item when it is long pressed, so I register the ListView for a context menu by calling <code>registerForContextMenu(historyListView)</code>. I've been trying to remove the row from the database by getting the row id in <code>OnCreateContextMenu</code> and storing it as a private field called <code>lastSelectedId</code>, then if the remove context item is selected in <code>OnContextItemSelected</code>, removing the row from the database by checking the <code>_id</code> column against <code>lastSelectedId</code>.</p>

<p>This isn't working.</p>

<p>So - 
(1.) is the row as given by </p>

<pre><code>public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;
        lastSelectedId = info.id;
</code></pre>

<p>the same as the _id column in the database?</p>

<p>and (2.) if not, how else can I delete the item in <code>onContextItemSelected()</code> based on the <code>_id</code> of the row in the database? </p>

<p>EDIT: Sorry about not explaining why this approach wasn't working more in-depth: What happens is that nothing happens when I attempt to delete the row: I call <code>mDB.delete(DB_TABLENAME,"_id=" + lastSelectedId, null);</code> on the database and then I call <code>bookmarksListAdapter.notifyDataSetChanged();</code> on my <code>SimpleCursorAdapter</code>. Then I see no change in the entries in my listview, which differs from my expected behavior that the row which I called remove on will disappear.</p>
