I want to get the current cursor entry, not just the identifier, so that I can manipulate the context menu.
I saw this example here which shows you how to get the id:
@Override public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case DELETE_ID: AdapterView.AdapterContextMenuInfo info= (AdapterView.AdapterContextMenuInfo)item.getMenuInfo(); delete(info.id); return(true); } return(super.onOptionsItemSelected(item)); }
This is great because it allows me to get the corresponding SQLite database identifier in the context menu with a click, which allows me to write a function to search for. But of course, can I just reuse the current cursor?
I tried to do this:
Cursor c = (Cursor) this.getListAdapter().getItem((int) info.id); String itemPriority = c.getInt(1); Log.v(TAG, "Current item:" + itemPriority);
but the cursor line seems to return only the database schema and not the record I am after.
Can someone shed some light.
EDIT: Thanks to @azgolfer, I found a solution. I use the fillData () method to populate the adapter. This is usually declared without variables. I had to override this method with a field variable. The relevant piece of code to make the curstor adapter visible in onContextItemSelected is here:
private void fillData() { Cursor itemsCursor = mDbHelper.fetchAllItemsFilter(mListId, mStatusFilter); startManagingCursor(itemsCursor); mItemAdaptor = new ItemAdapter(this, itemsCursor); this.setListAdapter(mItemAdaptor); }
source share