The onMenuItemSelected dispatches to either onOptionsItemSelected or onContextItemSelected.
If your onMenuItemSelected is overridden, could you ensure you're calling through to the super.onMenuItemSelected(...) implementation? jason On Tue, Apr 14, 2009 at 3:32 PM, Jack C. Holt <[email protected]> wrote: > > I have a ListActivity that I have registered a context menu for by > calling registerForContextMenu(getListView()). I have also overridden > onCreateContextMenu() as follows: > > public void onCreateContextMenu(ContextMenu menu, View v, > ContextMenuInfo menuInfo) { > super.onCreateContextMenu(menu, v, menuInfo); > menu.add(0, DELETE_ID, 0, R.string.really_delete); > } > > and onContextItemSelected() as follows: > > public boolean onContextItemSelected(final MenuItem item) { > switch (item.getItemId()) { > case DELETE_ID: > AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) > item.getMenuInfo(); > long bookId = menuInfo.id; > ContentResolver res = getContentResolver(); > Uri thisBookUri = ContentUris.withAppendedId(mBookUri, > bookId); > Cursor bookCurs = managedQuery(thisBookUri, > new String[] { YbkProvider.FILE_NAME }, null, > null, null); > > String fileName = bookCurs.moveToFirst() ? > bookCurs.getString(0) : null; > > File file = new File(fileName); > if (file.exists()) { > file.delete(); > } > > res.delete(ContentUris.withAppendedId(mBookUri, bookId), > null, > null); > > refreshBookList(); > > return true; > default: > return super.onContextItemSelected(item); > } > > } > > According to the documentation that I could find -- > http://developer.android.com/reference/android/app/Activity.html#onCreateContextMenu(android.view.ContextMenu,%20android.view.View,%20android.view.ContextMenu.ContextMenuInfo) > and http://developer.android.com/guide/topics/ui/menus.html -- > clicking the item context menu should cause onContextItemSelected() to > be called. > > Instead I noticed that Activity.onMenuItemSelected() was being > called. Weird? > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

