mariomario
mariomario

Reputation: 660

Actionbarsherlock back button doesn't go back

When I press the home button it doesn't go back like I think it would do.

public class TotalOverview extends SherlockActivity {

public void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Theme_Sherlock);       
    super.onCreate(savedInstanceState);         
    //requestWindowFeature(Window.FEATURE_PROGRESS);  

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    setContentView(R.layout.main); 
    //getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

}

I also tried catching it with this method

public boolean onOptionsItemSelected(MenuItem item)
{
    boolean toReturn = false;
    int id = item.getItemId();  
    if( id == R.id.abs__home)
    {
        toReturn = true;
    }
    return toReturn;
}

but that didn't work I did get into this method but the id is not the same id as the R.id.abs__home. So how can I get this to work.

The emulator I am using has android version 2.3.1. For the rest everything from the actionbarsherlock works like expected.

The blue block is the button I click, and with clicking that I want to navigate back. enter image description here

Upvotes: 11

Views: 13040

Answers (2)

FreezeIt
FreezeIt

Reputation: 11

it's bug and it's was reported here https://groups.google.com/forum/?fromgroups=#!topic/actionbarsherlock/dsZr7z4_xvU

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1007276

Use android.R.id.home to detect the home affordance, not R.id.abs__home. For example, from this sample project, using ABS 4.0.2:

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        pager.setCurrentItem(0, false);
        return(true);

    // more code here for other cases
  }

Upvotes: 43

Related Questions