Aathira
Aathira

Reputation: 23

How to switch between tabs in Android?

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.

Upvotes: 2

Views: 2491

Answers (3)

Dijo David
Dijo David

Reputation: 6195

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.

Upvotes: 0

FrVaBe
FrVaBe

Reputation: 49341

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>)

Upvotes: 4

Heiko Rupp
Heiko Rupp

Reputation: 30934

You can use Tabhost.setCurrentTab(number) for this purpose

Upvotes: 0

Related Questions