问题
How do I switch between tabs from within one of the activities that is located inside the tab host? I need to complete the project by tomorrow. My project involves showing 3 tabs with varying content. So please help anyone.
回答1:
If you added the tabs as activities you can use this code inside a tab child activity
TabActivity main = (TabActivity) getParent(); // get the main 'TabActivity' from a Child (tab)
TabHost tabHost = main.getTabHost(); // get a handle to the TabHost
tabHost.setCurrentTab(<index>)
回答2:
You can use Tabhost.setCurrentTab(number)
for this purpose
回答3:
This discussion will help u. In my case GrandPrix's solution helped me.
EDIT:
Go through the follwing links:
Development Guide
Programming Android
Android Development Tutorial (Gigerbread - V 1.3)
Layout Tutorial
Also there will be having some sample codes in the Android SDK. You can find the code under 'samples' folder. You can install the 'APIDemos' sample package to your emulator to get an idea about almost evey part of the android.
来源:https://stackoverflow.com/questions/5430759/how-to-switch-between-tabs-in-android