Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 948
mariomario Avatar asked May 04 '12 13:05

mariomario


2 Answers

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
  }
like image 114
CommonsWare Avatar answered Sep 30 '22 17:09

CommonsWare


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

like image 34
FreezeIt Avatar answered Sep 30 '22 17:09

FreezeIt