can someone explain me the difference between:
onMenuItemSelected (int featureId, MenuItem item)
http://developer.android.com/reference/android/app/Activity.html#onMenuItemSelected%28int,%20android.view.MenuItem%29
and
onOptionsItemSelected (MenuItem item)
http://developer.android.com/reference/android/app/Activity.html#onOptionsItemSelected%28android.view.MenuItem%29
in Android? I found a tutorial were someone overrides both methods.
// Reaction to the menu selection @Override public boolean onMenuItemSelected(int featureId, MenuItem item) { switch (item.getItemId()) { case R.id.insert: createTodo(); return true; } return super.onMenuItemSelected(featureId, item); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.insert: createTodo(); return true; } return super.onOptionsItemSelected(item); }
Source: http://www.vogella.de/articles/AndroidSQLite/article.html
Android knows about several types of menus (e.g. Options Menu and Context Menu). onMenuItemSelected
is the generic callback. You don't need to use this usually. onOptionsItemSelected
is the callback of the options menu and onContextItemSelected
is the callback of the context menu. Use these two specific ones instead.
Using ADT 17 (version 4.2) the onOptionsItemSelected
callback will allow the user to access menu options from any context including the Menu Button and the Action Bar. As of Android version 3.0 the preferred method is the Action Bar which can be accessed from onMenuItemSelected
. If you are designing an app that supports versions 2.3 or earlier than onOptionsItemSelected
is the way you want to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With