I'm making an Android app that uses the action bar tabs (I'm using the support library's action bar), each associated with a fragment that I generate dynamically.
The idea is to show the fragment whenever its tab is selected using FragmentTransaction.show() and hide the deselected tab with FragmentTransaction.hide(), but when I do this, the 'hidden' fragment simply becomes slightly greyed out.
The fact that the UI indicates that something is different by greying out the hidden tab might suggest that this is intentional behavior, but I was under the impression that hide() actually hid the tabs.
What am I doing wrong and what should I do? The code for the tab listener is below if necessary:
public class VarientTabListener implements ActionBar.TabListener
{
VarientFragment Arch_Fragment;
VarientFragment Plane_Fragment;
ActionBarActivity parent;
public VarientTabListener(ActionBarActivity act)
{
parent = act;
}
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft)
{
//Work out which tab was selected
if (tab.getText() == "Arch_Tab")
{
//Create the tab if it doesn't exist
if (Arch_Fragment == null)
{
Arch_Fragment = (VarientFragment) Fragment.instantiate(parent, VarientFragment.class.getName());
ft.add(android.R.id.content, Arch_Fragment, "Arch");
}
//Otherwise show it
else
{
ft.show(Arch_Fragment);
}
}
else if (tab.getText() == "Plane_Tab")
{
if (Plane_Fragment == null)
{
Plane_Fragment = (VarientFragment) Fragment.instantiate(parent, VarientFragment.class.getName());
ft.add(android.R.id.content, Plane_Fragment, "Plane");
}
else
{
ft.show(Plane_Fragment);
}
}
}
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft)
{
if (tab.getText() == "Arch_Tab")
{
if (Arch_Fragment != null)
{
//Hide the unselected tab
ft.hide(Arch_Fragment);
}
}
else if (tab.getText() == "Plane_Tab")
{
if (Plane_Fragment != null)
{
ft.hide(Plane_Fragment);
}
}
}
@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft)
{
}
}