java – How to implement tabs now that TabActivity is deprecated-ThrowExceptions

Exception or error:

I am trying to implement some simple tabs in an activity.
I think I have the xml code ok (I am using the minimal tabHost/widget/FrameLayout found in example code), I am however having issues with the java side.
Most of the documentation on how to do this point to using TabWidget, this class is now deprecated. It is suggested that one should use fragments. But fragments seem to be used in a rather different manner.
Has someone go some sample code of how to implement in java some very basic tabs defined in an xml file now that TabHost is deprecated.(the example [here[1 does not use xml )

How to solve:

If you go to the Android developer guide they show you how this can be done

http://developer.android.com/reference/android/app/TabActivity.html

There is example code that shows you how to do this using fragments

###

Create your tabs using fragments.

A good example:
http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/

And, of course, you should read about fragmentActivities in the official documentation:
http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html

Search for more – there are many other examples how to create tabs in this way.

###

Create include Linearlayout with small images and implement interface with navigation to this images(tabs),

public interface Tabs {

    public void moveToTab1();
    public void moveToTab2();
    public void moveToTab3();
    public void moveToTab4();
}

public Activity implements Tabs {

    public void moveToTab1() {
        startActivity();
        finish();
    }
}

// other methods

Leave a Reply

Your email address will not be published. Required fields are marked *