Switch between tabs in a fragment tabhost
android, android-fragments, android-tabhost
Solution
In Tab Fragment:
public void setCurrentTab(int tab_index){
mTabHost = (FragmentTabHost)getActivity().findViewById(android.R.id.tabhost);
mTabHost.setCurrentTab(tab_index);
}
In click event of the button of DialogFragment:
FragmentTabHost tabHost = (FragmentTabHost) getActivity().findViewById(android.R.id.tabhost);
tabHost.setCurrentTab(3);
Problem
- I have a FragmentTabHost, hosted in a Fragment. The tabHost has 4 tabs. - In first tab fragment, there are two nested fragments. - After clicking in a view in first nested fragment, a DialogFragment appears, which has a couple of buttons. After clicking on a button in DialogFragment, I want to switch to tab number 3. How can I do this?