I have implemented a TabActivity
which extends FragmentActivity
. It has 5 tabs each tab is a Fragment
. What i am looking for is to switch between the tabs programmatically.
For eg: if i am in tab4. On button click I want to move from tab4
to tab1
. Tried a lot but couldn't find the solution for this.
Tried with the following but it doesn't help.
From SecondTab
public void switchTabInActivity(String value){
FirstTab parent;
parent = (FirstTab) getActivity().getParent();
parent.switchTab(value);
}
TabActivity
/** To Change Tab*/
public void switchTab(String tabno){
this.onTabChanged(tabno);
}
android.R.id.tabhost
will throw a nullpointerexception. You are already callinggetActivity.findViewById
findViewById(R.id.tabhost)
is the right option – Hoagland