开发者

Navigation between tabs in TabHost

开发者 https://www.devze.com 2023-01-06 08:49 出处:网络
Is there a possibility to navigate between Activities ta开发者_Go百科bs in TabHost using back button? When I press it, I go out of the main Activity to the previous one. You could keep track of the pr

Is there a possibility to navigate between Activities ta开发者_Go百科bs in TabHost using back button? When I press it, I go out of the main Activity to the previous one.


You could keep track of the previously selected tab using the TabHost's setOnTabChangedListener() method and then override your Activity's onBackPressed() method to setCurrentTabByTag() on the TabHost, but think really really hard before you do this, since it's not at all the expected behavior for Android users interacting with a tabbed activity.

Name one other popular Android application that does this. Then explain why your app will be different than these and how changing the expected behavior will do anything other than confuse and annoy users. If you can do that, have at it; otherwise, think long and hard about whether tabs are even the right metaphor for your app. Perhaps the Dashboard pattern (item 3 at the link) is more suitable for your case?


That's the way a TabHost works. It contains the tabs within itself, so hitting the Back button is backing out of the TabHost, not the Activity contained within a particular tab.

I suppose there's probably some way you could override the Back button and fake it.

0

精彩评论

暂无评论...
验证码 换一张
取 消