Can TabHost be used in another Android element?

I am trying to configure the tab host as a layout element. All the examples I've seen display TabHost on their own in the view. The examples work fine, but when I try to make it part of another layout, it doesn't seem to work. I never found the documentation pointing anyway.

Something like this works (not all code is shown for illustration):

            <TabHost>
                    <LinearLayout>
                        <TabWidget/>
                        <FrameLayout>
                            <TextView
                                android:text="this is a tab" />
                            <TextView
                                android:text="this is another tab" />
                            <TextView
                                android:text="this is a third tab" />
                        </FrameLayout>
                    </LinearLayout>
            </TabHost>

However, this does not work:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">

                                                                                                       

Am I doing something wrong or is it simply impossible?

This is my onCreate method:

public class MyActivity extends Activity {

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

    }
}

Is there anything you need to install there?

When I say that this does not work, I mean that after starting the application in the emulator I get a pop-up message: "The application xxx (process com.example) stopped unexpectedly. Try again."

, . android 1.6, .

+3
1

!!

, , , , , TabHost, .

onCreate(). , ( - ) , xml.

My onCreate : ( , , )

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

    TabHost mTabHost = getTabHost();
    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("Tab 1").setContent(R.id.textview1));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("Tab 2").setContent(R.id.textview2));
    mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("Tab 3").setContent(R.id.textview3));

    mTabHost.setCurrentTab(0);        

}
+1

Source: https://habr.com/ru/post/1770806/


All Articles