Anton
Anton

Reputation: 225

How to call back button in Action Tab

Please help me.

I use onOptionsItemSelected to get to settings layout. There I activate setDisplayHomeAsUpEnabled

public boolean onOptionsItemSelected(MenuItem settings){
                    setContentView(R.layout.settings);
                    getActionBar().setDisplayHomeAsUpEnabled(true);
                    return super.onOptionsItemSelected(settings);
}

enter image description here

How can I get back to main layout from settings layout?

Upvotes: 2

Views: 268

Answers (1)

Cheesebaron
Cheesebaron

Reputation: 24460

In onOptionsItemSelected you need to find out whether the MenuItem that is clicked is your Home item.

I would use a switch like:

switch (settings.getItemId()) {
    // If home icon is clicked return to main Activity
    case android.R.id.home:
      Intent intent = new Intent(this, MainActivity.class);
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      startActivity(intent);
      break; 
}

Then I would either start the MainActivity again or just call finish() to end the current one. There is a very nice article with loads of samples which you might find useful here: http://www.vogella.com/articles/AndroidActionBar/article.html

Upvotes: 2

Related Questions