0

I wanted to do app with tabhost. Every tab has other layout. And in every layout I want to use other activities. Is it possible? How to do it?

I've done something like this:

myTabHost =(TabHost) findViewById(R.id.TabHost);

            myTabHost.setup(this.getLocalActivityManager());
        // Adding tabs

            // tab1 settings
        TabSpec spec = myTabHost.newTabSpec("tab_creation");
        spec.setIndicator("Strona główna",getResources().getDrawable(android.R.drawable.ic_menu_add));          
        Intent i = new Intent().setClass(this, WelcomeActivity.class);
        spec.setContent(i);
        myTabHost.addTab(spec);  

        // otherwise :
        Intent j = new Intent().setClass(this, DrugsActivity.class);
        myTabHost.addTab(myTabHost.newTabSpec("tab_inser").setIndicator("Lista leków",getResources().getDrawable(android.R.drawable.ic_menu_edit)).setContent(j)); 
        Intent k = new Intent().setClass(this, SymptomsActivity.class);
        myTabHost.addTab(myTabHost.newTabSpec("tab_affiche").setIndicator("Objawy",getResources().getDrawable(android.R.drawable.ic_menu_view)).setContent(k));           

        myTabHost.setCurrentTab(0);

But now it looks that app show me every layout on ONE screen. They're superposed... I haven't idea what to change cause I just start my adventure with android&java. Could anyone help me?

Szymon
  • 42,577
  • 16
  • 96
  • 114

1 Answers1

0

You cannot use multiple activities at the same time. You can use multiple fragments and each fragment can have its own layout. In your case you should have:

  • one activity
  • a tabhost inside that activity
  • one fragment for each tab.
Szymon
  • 42,577
  • 16
  • 96
  • 114
  • Thanks for answer, but I'm not sure I understand everything - my english is not very well. HERE: http://androidcodeexamples.blogspot.in/2012/08/multiple-android-activities-in.html is example I was inspiring. Here is other activity for every tab. I've just did not use ActivityStack.java, but other my classes are very similar. So why I can't use something like this in my app? :) I would like to understand it. – user3163355 Jan 05 '14 at 20:45
  • The code in this blog targets Android 2.2 (API 8) which is pretty old by now. What it's trying to do is now done by using fragments. You can also use fragments in API 2.X with compat library so it's best to go with the new way. – Szymon Jan 05 '14 at 22:20
  • sir Please answer this question [link](http://stackoverflow.com/questions/20988505/open-child-activity-in-tab-host-android) – Bishnu Kumar Jan 08 '14 at 07:20