I am trying to switch between tabs (ActionBarActivity) from within a fragment that is attached to one of the tabs.
I found this solution:
TabHost host = (TabHost) getActivity().findViewById(android.R.id.tabhost);
host.setCurrentTab(2);
but the app crashes when executed, with a NullPointerException at the second line. If I try and get any information about host
, it all comes back null.
I don't have much Android experience, and so am unsure how to properly get a reference to the parent activity that holds the fragment.
EDIT
I'm not sure if this makes a difference, but I've moved the default SectionsPagerAdapter
to a class of its own.