Search code examples
androidactionbarsherlock

How to check if the back button of the ActionBarSherlock was clicked?


I'm using the library ActionBarSherlock, and put a item with the property android:showAsAction="ifRoom|collapseActionView". How to check if the back button of the ActionBarSherlock was clicked? thanks!


Solution

  • you have to override

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
    
        }
        return true;    
    }
    

    from the doc:

    his hook is called whenever an item in your options menu is selected. The default implementation simply returns false to have the normal processing happen (calling the item's Runnable or sending a message to its Handler as appropriate). You can use this method for any items for which you would like to do processing without those other facilities.