Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8383205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:06:30+00:00 2026-06-09T17:06:30+00:00

Below is my layout xml file: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android xmlns:tools=http://schemas.android.com/tools android:id=@+id/LinearLayout1 android:layout_width=match_parent android:layout_height=match_parent android:orientation=horizontal >

  • 0

Below is my layout xml file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/l1"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="right"
        android:orientation="vertical" >

        <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@drawable/ic_launcher">

    <RelativeLayout
        android:id="@+id/RelativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true" android:background="#FF888888"/>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentLeft="true"
            android:layout_above="@android:id/tabs" />
    </RelativeLayout>

</TabHost>
    </LinearLayout>


    <LinearLayout
        android:id="@+id/l2"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
        android:background="#000000"
        android:orientation="vertical" >


        <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@drawable/ic_launcher">

    <RelativeLayout
        android:id="@+id/RelativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true" android:background="#FF888888"/>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentLeft="true"
            android:layout_above="@android:id/tabs" />
    </RelativeLayout>

</TabHost>
    </LinearLayout>

</LinearLayout>

There 2 tabhost in layout l1 and l2.
And below code is mine to use tabhost:

TabWidget tw;
TabHost tabHost;
tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent; 
Resources res = getResources();
    tw = (TabWidget)findViewById(android.R.id.tabs);

intent = new Intent().setClass(this, MyGroup.class);
spec = tabHost.newTabSpec("A").setIndicator("A", res.getDrawable(R.drawable.ic_action_search)).setContent(intent);
tabHost.addTab(spec);

intent = new Intent().setClass(this, MyGroup.class);
spec = tabHost.newTabSpec("B").setIndicator("B", res.getDrawable(R.drawable.ic_action_search)).setContent(intent);
tabHost.addTab(spec);

intent = new Intent().setClass(this, MyGroup.class);
spec = tabHost.newTabSpec("C").setIndicator("C", res.getDrawable(R.drawable.ic_action_search)).setContent(intent);
tabHost.addTab(spec);

But it can only control the tabhost in l1.
How can I do to control the tabhost in l2?

I make some modify as below:

    private TabWidget tw;
    private TabHost tabHost;
    private TabWidget tw1;
    private TabHost tabHost1;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        tabHost = getTabHost();
        TabHost.TabSpec spec;
        Intent intent; 
        Resources res = getResources();
        tw = (TabWidget)findViewById(android.R.id.tabs);

        intent = new Intent().setClass(this, MyGroup.class);
        spec = tabHost.newTabSpec("A").setIndicator("A", res.getDrawable(R.drawable.ic_action_search)).setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, MyGroup.class);
        spec = tabHost.newTabSpec("B").setIndicator("B", res.getDrawable(R.drawable.ic_action_search)).setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, MyGroup.class);
        spec = tabHost.newTabSpec("C").setIndicator("C", res.getDrawable(R.drawable.ic_action_search)).setContent(intent);
        tabHost.addTab(spec);
        intent = new Intent().setClass(this, MyGroup.class);
        spec = tabHost.newTabSpec("A").setIndicator("A", res.getDrawable(R.drawable.ic_action_search)).setContent(intent);
        tabHost.addTab(spec);



        tabHost1 = (TabHost)findViewById(R.id.tabhost1);
        TabHost.TabSpec spec1;
        Intent intent1; 
        tw1 = (TabWidget)findViewById(android.R.id.tabs);

        intent1 = new Intent().setClass(this, MyGroup.class);
        spec1 = tabHost1.newTabSpec("D").setIndicator("D", res.getDrawable(R.drawable.ic_action_search)).setContent(intent1);
        tabHost1.addTab(spec1);

        intent1 = new Intent().setClass(this, MyGroup.class);
        spec1 = tabHost1.newTabSpec("E").setIndicator("E", res.getDrawable(R.drawable.ic_action_search)).setContent(intent1);
        tabHost1.addTab(spec1);

        intent1 = new Intent().setClass(this, MyGroup.class);
        spec1 = tabHost1.newTabSpec("F").setIndicator("F", res.getDrawable(R.drawable.ic_action_search)).setContent(intent1);
        tabHost1.addTab(spec1);
        intent1 = new Intent().setClass(this, MyGroup.class);
        spec1 = tabHost1.newTabSpec("G").setIndicator("G", res.getDrawable(R.drawable.ic_action_search)).setContent(intent1);
        tabHost1.addTab(spec1);
}

And error message is below:

08-14 16:26:26.960: D/AndroidRuntime(9763): Shutting down VM
08-14 16:26:26.960: W/dalvikvm(9763): threadid=1: thread exiting with uncaught exception (group=0x40a291f8)
08-14 16:26:26.960: E/AndroidRuntime(9763): FATAL EXCEPTION: main
08-14 16:26:26.960: E/AndroidRuntime(9763): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testtwolayout/com.example.testtwolayout.MainActivity}: java.lang.NullPointerException
08-14 16:26:26.960: E/AndroidRuntime(9763):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
08-14 16:26:26.960: E/AndroidRuntime(9763):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-14 16:26:26.960: E/AndroidRuntime(9763):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-14 16:26:26.960: E/AndroidRuntime(9763):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-14 16:26:26.960: E/AndroidRuntime(9763):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-14 16:26:26.960: E/AndroidRuntime(9763):     at android.os.Looper.loop(Looper.java:137)
08-14 16:26:26.960: E/AndroidRuntime(9763):     at android.app.ActivityThread.main(ActivityThread.java:4424)
08-14 16:26:26.960: E/AndroidRuntime(9763):     at java.lang.reflect.Method.invokeNative(Native Method)
08-14 16:26:26.960: E/AndroidRuntime(9763):     at java.lang.reflect.Method.invoke(Method.java:511)
08-14 16:26:26.960: E/AndroidRuntime(9763):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-14 16:26:26.960: E/AndroidRuntime(9763):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-14 16:26:26.960: E/AndroidRuntime(9763):     at dalvik.system.NativeStart.main(Native Method)
08-14 16:26:26.960: E/AndroidRuntime(9763): Caused by: java.lang.NullPointerException
08-14 16:26:26.960: E/AndroidRuntime(9763):     at android.widget.TabHost.addTab(TabHost.java:232)
08-14 16:26:26.960: E/AndroidRuntime(9763):     at com.example.testtwolayout.MainActivity.onCreate(MainActivity.java:68)
08-14 16:26:26.960: E/AndroidRuntime(9763):     at android.app.Activity.performCreate(Activity.java:4465)
08-14 16:26:26.960: E/AndroidRuntime(9763):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-14 16:26:26.960: E/AndroidRuntime(9763):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
08-14 16:26:26.960: E/AndroidRuntime(9763):     ... 11 more

The line MainActivity.java:68 means line tabHost1.addTab(spec1);

I have resolve by this Android: TabHost without TabActivity .
And simple test code as below:

    private LocalActivityManager mlam;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        mlam = new LocalActivityManager(this, false);
        mlam.dispatchCreate(savedInstanceState);

        tw = (TabWidget)findViewById(android.R.id.tabs);
        Resources res = getResources();



        tabHost =(TabHost)findViewById(android.R.id.tabhost);
        tabHost.setup(mlam);
        TabHost.TabSpec spec;
        Intent intent; 

        intent = new Intent().setClass(this, MyGroup.class);
        spec = tabHost.newTabSpec("A").setIndicator("A", res.getDrawable(R.drawable.ic_action_search)).setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, MyGroup.class);
        spec = tabHost.newTabSpec("B").setIndicator("B", res.getDrawable(R.drawable.ic_action_search)).setContent(intent);
        tabHost.addTab(spec);



        tabHost1 = (TabHost)findViewById(R.id.tabhost1);
        tabHost1.setup(mlam);
        TabHost.TabSpec spec1;
        Intent intent1;


        intent1 = new Intent().setClass(this, MyGroup.class);
        spec1 = tabHost1.newTabSpec("C").setIndicator("C", res.getDrawable(R.drawable.ic_action_search)).setContent(intent1);
        tabHost1.addTab(spec1);

        intent1 = new Intent().setClass(this, MyGroup.class);
        spec1 = tabHost1.newTabSpec("D").setIndicator("D", res.getDrawable(R.drawable.ic_action_search)).setContent(intent1);
        tabHost1.addTab(spec1);
        tabHost1.setCurrentTab(0);
}

And MyGroup is below:

public class MyGroup extends ActivityGroup {
    public static ActivityGroup group;  

    @Override  
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState);  
        group = this;  
    }  

    @Override  
    public void onBackPressed() {  
        group.getLocalActivityManager().getCurrentActivity().onBackPressed();  
    }  

    @Override  
    protected void onResume() {  
        super.onResume();  
        Intent it;
        Window w;
        View view;

        it = new Intent(this, AActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  
        w = group.getLocalActivityManager().startActivity("AActivity", it);  
        view = w.getDecorView();  
        group.setContentView(view);
    }
}

And AActivity as below only show a random number:

public class AActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.a);

        TextView tv = (TextView)findViewById(R.id.atv);
        int x = (int)(Math.random()*42+1);
        String xx = Integer.toString(x);
        Log.d("q", xx);
        tv.setText(xx);

    }
}

But I find the left layout’s tab 0 will not show number.
But the line Log.d(“q”, xx); is show.
How about this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:06:32+00:00Added an answer on June 9, 2026 at 5:06 pm

    You cant get hold of two different tabhosts by using the same id. Therefore, you must need to change the android:id of your second tabhost.

    For example: android:id="@+id/mySecondTabhost"

    And later you need to use proper R class which refers to your package (not android.R) in order to retrieve your custom defined id value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got the following layout XML file: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/main_layout android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical> <GridView
This is the basic XML file <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical
I've created custom dialog (from xml file), like below: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical
My layout.xml file looks like this: <ScrollView xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/scrollView1 android:layout_width=fill_parent android:layout_height=270dp android:layout_weight=0.47 > <LinearLayout
I am working with layout like in below xml code <?xml version=1.0 encoding=utf-8?> <LinearLayout
I have a listView with custom objects defined by the xml-layout below. I want
XML Code: <GridLayout android:id=@+id/grid android:layout_width=fill_parent android:layout_height=fill_parent android:layout_above=@+id/step android:layout_alignParentLeft=true android:layout_alignParentRight=true android:layout_below=@+id/menu > </GridLayout> The above
I have made following relative layout in an xml file lets say add_relative_layout.xml <?xml
I tried to make a file choose following the below link http://www.dreamincode.net/forums/topic/190013-creating-simple-file-chooser/ However, I
I have a xml file for layout of each row of listview. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.