1

I'm looking for an example, like the standard "Tab Layout" tutorial that uses BOTH activities for each tab and a dedicated xml layout file for each tab.

Can anyone help. All the examples I've found simply use the following for the layout

TextView textview = new TextView(this);
textview.setText("This is the Artists tab");
setContentView(textview);

The reason for using activities is that for one of the tabs I want to force a landscape orientation.

Cristian
  • 198,401
  • 62
  • 356
  • 264
John Greening
  • 13
  • 1
  • 4
  • this tutorial might help you http://learnncode.wordpress.com/2013/12/18/how-to-use-tabwidget-with-fragments/ – Prachi Dec 23 '13 at 11:35

3 Answers3

1

Try here:

http://www.androidpeople.com/android-tabhost-tutorial-part-1

If you need any help with this let me know because I have a fully customized TabHost in my APP's.

Thanks

Derek Williams
  • 525
  • 6
  • 21
1

The Tab Layout Tutorial shows how to use separate activities for each tab's content. Just combine it with the following code snippet:

TabHost.TabSpec spec = tabHost.newTabSpec("layout tab")
   .setIndicator("Layout based tab")
   .setContent(new TabHost.TabContentFactory(){
      public View createTabContent (String tag) {
         return getLayoutInflater().inflate(R.layout.layout_tab, null);
      }
});

tabHost.addTab(spec);

Intent intent = new Intent().setClass(this, MyActivity.class);
spec = tabHost.newTabSpec("activity tab")
   .setIndicator("Activity based tab")
   .setContent(intent);

tabHost.addTab(spec);
Dan S
  • 9,139
  • 3
  • 37
  • 48
1

Looking for a universal TabHost style that will work on Android, HTC Sense, Samsung, etc. skins

In addition to that in your ActivityGroup:

public class YourActivityGroup extends ActivityGroup {

private List<View> viewCache;

public void replaceView(View view) {
    if (viewCache == null) {
        viewCache = new ArrayList<View>();
    }
    viewCache.add(view);
    setContentView(view);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Replace the view of this ActivityGroup
    replaceView(startYourActivity());
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // handling rotation
    resetCache();

    // reset the ui
    replaceView(startYourActivity());
}

private View startYourActivity() {
    // Start the root activity withing the group and get its view
    return getLocalActivityManager().startActivity(YourActivity.class.getSimpleName(),
            new Intent(this, YourActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
}

/**
 * Clears the View cache.
 */
public void resetCache() {
    viewCache = new ArrayList<View>();
}

@Override
public void onBackPressed() {
    this.back();
}

}

Rest is easy.^^

Community
  • 1
  • 1
einschnaehkeee
  • 1,858
  • 2
  • 17
  • 20