Reputation: 225
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);
}
How can I get back to main layout from settings layout?
Upvotes: 2
Views: 268
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