Search code examples
androidandroid-3.0-honeycombandroid-4.0-ice-cream-sandwich

switching tabs in Android


Basically Android 2.2 and all support older version of tabs, where in we just have to pass the intent for the tab handler which manages loading and handling the activities.

How to do the same in Android 3.0 or 4.0, how to set intent for Tab object? with fragments we can do, but it must be optional right?

Here is the sample code of Tabs in 4.0

ActionBar.Tab tab1 = getSupportActionBar().newTab();

    tab1.setText("Hello");
    tab1.setIcon(R.drawable.ic_search);
    tab1.setTabListener(this);

    getSupportActionBar().addTab(tab1);

Any idea, how to add the intent for the corresponding tab?


Solution

  • Basically Android 2.2 and all support older version of tabs, where in we just have to pass the intent for the tab handler which manages loading and handling the activities.

    That approach has been deprecated.

    How to do the same in Android 3.0 or 4.0, how to set intent for Tab object?

    You don't. That approach has been deprecated.

    with fragments we can do, but it must be optional right?

    Your TabListener is welcome to use fragments, or simply update the content view of your activity.