Michael Zeuner
Michael Zeuner

Reputation: 1776

Stopping tabs from changing

What I need unless my tablet is connected to a server I cant have the tabs being changed. I have a tab host that is all run off of the same java file. I figure all I need to do is have some sort of a test in the file to say unless boolean is true dont let the code change the tab. However I dont know how to do this? If you need to see any of my code just leave that in the comment box. Thanks for all your help !

Upvotes: 0

Views: 76

Answers (1)

marmor
marmor

Reputation: 28179

Well I guess you can try disabling/enabling clicks on the tabs by calling:

myTabHost.getTabWidget().setClickable(isConnectedToServer);

But I'm not sure that's good UX, how about letting your users change tabs, but if the content can't be reached displaying a message inside the main view of the tab "server unreachable, check your internet connection" or something like that.

UPDATE: Try this instead (for each of your tabs):

myTabHost.getTabWidget().getChildTabViewAt(0).setEnabled(false);
myTabHost.getTabWidget().getChildTabViewAt(1).setEnabled(false);
myTabHost.getTabWidget().getChildTabViewAt(2).setEnabled(false);

ANOTHER UPDATE:

public class MyActivity extends Activity {
    private TabWidget mTabWidget = null;
    protected void onCreate(Bundle savedInstanceState) {
    ...
    mTabWidget = myTabHost.getTabWidget();
    ...
}

protected void refreshTabs(boolean isConnected) {
    mTabWidget.getChildTabViewAt(0).setEnabled(isConnected);
    mTabWidget.getChildTabViewAt(1).setEnabled(isConnected);
    mTabWidget.getChildTabViewAt(2).setEnabled(isConnected);
}

Now you can call refreshTabs whenever you want in your code to make them enabled/disabled.

Upvotes: 1

Related Questions