I'm developing an application that uses the new Tabs system (ActionBar.addTab()), I will have 3 tabs. During a determined process I would like to lock (disable) two of them (not remove, only do not accept clicks and not change the 'selector'.
I was able to do not change the content (by implementing the TabListener and not changing the fragment, etc) but the selector changes.
Is there anyway to only disable/enable the tabs? without have to remove and add again?
Thanks in advance! BR, Danilo
Sorry, there is no "enable" or "disable" with tabs in the action bar. As you note, you can remove and re-add them -- that is the closest you can get AFAIK.
I got into the exact same issue. Finally was able to solve it. As said already, there is no way to disable/enable a tab. There is only one way out - and that is to go back to the previous tab using
getActionBar().setSelectedNavigationItem(tab);
Note however, that this should NOT be done from within the
onTabSelected(ActionBar.Tab tab,FragmentTransaction fragmentTransaction)
method, because then it gets stuck in recursive loop. So within the onTabSelected() - send a messsage to the Activity Handler to do the setSelectedNavigation().
One catch here is (you will know when you implement): what "tab" value to pass in the setSelectedNavigation. For this, we have to keep track of whether it is a user pressed tab switch or forced switch to the last tab via the code.
For this:
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
if (forcedTabSwitch)
forcedTabSwitch = false;
else
mTabToBeSwitchedTo = tab.getPosition();
}
and in the Handler,
switch (msg.what) {
case SWITCH_TO_TAB :
forcedTabSwitch = true;
break;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With