How to switch between tabs in Android?

╄→尐↘猪︶ㄣ 提交于 2019-12-11 04:15:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!