Libathos
Libathos

Reputation: 3362

Can't listen for clicks at ActionItems

I'm using actionBarSherlock in a device with android v 2.3.6 and I can't listen to the clicks in the ActionItems whereas this doesn't happen when I run the app in the emulator android 4.1 is there a compatibility problem? can something be done?

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    BitmapDrawable bg = (BitmapDrawable)getResources().getDrawable(R.drawable.barbitmap);
    bg.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
    getSupportActionBar().setBackgroundDrawable(bg);


    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}


        @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item) {


        int itemId = item.getItemId();
        System.out.println(itemId);

        if(itemId==android.R.id.home){
            finish();
            return false;
        }   
        return false;
    }

Upvotes: 0

Views: 54

Answers (3)

keshav
keshav

Reputation: 3255

Make sure you are importing this

import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;

not this

import android.view.Menu;
import android.view.MenuItem;

then use

@Override
    public boolean onOptionsItemSelected(MenuItem item)
    {

        int id = item.getItemId();
        switch (id)
        {
        case R.id.action_bar_menu_refresh:
         }
    }

Upvotes: 1

coder
coder

Reputation: 13250

public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                // Navigate "up" the demo structure to the launchpad activity.
                // See http://developer.android.com/design/patterns/navigation.html for more.

                return true;

           }

        return super.onOptionsItemSelected(item);
    }

Upvotes: 1

M-Wajeeh
M-Wajeeh

Reputation: 17284

Try overriding onOptionItemnSelected() instead.

Upvotes: 0

Related Questions