Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 4.0 development - onMenuItemSelected(int,Menu)

Tags:

android

I ve just upgraded my Android application from api level 13 to 14, using simulator 4.0.

Can anyone that is using level 14 api confirm that there is a problem with

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item)
{
switch(item.getItemId())
           {
                case android.R.id.home:
...
}

function ? If i compile with level 13 api, i can click on the main activity icon ( left up) and i go to this method in r.id.home case, but with upgrading to api level 14 that function is not called and it looks like the icon is not clickable :(

I am just wondering if it is a bug in this just newly released api..

like image 621
2low.samurai Avatar asked Nov 18 '11 23:11

2low.samurai


2 Answers

From the Action Bar documentation:

Note: If you're using the icon to navigate to the home activity, beware that beginning with Android 4.0 (API level 14), you must explicitly enable the icon as an action item by calling setHomeButtonEnabled(true) (in previous versions, the icon was enabled as an action item by default).

like image 74
ekawas Avatar answered Nov 15 '22 07:11

ekawas


I'm not sure about the overload you're using for onOptionsItemSelected. The Android reference shows that the only overload is onOptionsItemSelected(MenuItem) and the following is definitely working for me:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
like image 42
Guykun Avatar answered Nov 15 '22 07:11

Guykun