在得到在我的活动Tabhost错误我的、错误、Tabhost

2023-09-04 06:52:00 作者:最完整的数字是十二

当我试图让我的活动选项卡主机它显示了你忘了叫公共无效设置(LocalActivityManager的ActivityGroup)

 公共类MainActivity扩展FragmentActivity {
    私人资源资源;
    私人TabHost tabHost;

    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);

        // tabHost = getTabHost();
        TabHost tabHost =(TabHost)findViewById(android.R.id.tabhost);

            tabHost.setup();

        RES = getResources();

        意图int​​entContact =新意图()。setClass(这一点,
                tabOne_Activity.class);
        则tabspec tabSpecContact = tabHost.newTabSpec(聊天)
                .setIndicator(,res.getDrawable(R.drawable.ic_launcher))
                .setContent(intentContact);
        tabHost.addTab(tabSpecContact);

        意图int​​entChat =新意图()setClass(这一点,tabTwo_Activity.class)。
        则tabspec tabSpecChat = tabHost.newTabSpec(聊天)
                .setIndicator(,res.getDrawable(R.drawable.ic_launcher))
                .setContent(intentChat);
        tabHost.addTab(tabSpecChat);

        意图int​​entProfile =新意图()。setClass(这一点,
                tabThree_Activity.class);
        则tabspec tabSpecProfile = tabHost.newTabSpec(聊天)
                .setIndicator(,res.getDrawable(R.drawable.ic_launcher))
                .setContent(intentProfile);
        tabHost.addTab(tabSpecProfile);

        tabHost.setCurrentTab(2);


    }
}
 

解决方案 Android Tabhost选项卡

您要使用tabhost.For,你必须扩展 TabActivity

写低于code中的onCreate():

  LocalActivityManager mlam =新LocalActivityManager(这一点,假);
        mlam.dispatchCreate(savedInstanceState);
        // tabHost = getTabHost();
        //tabHost.setup();
        tabHost.setup(mlam);
 

When I am trying to get the tab host in my activity it is showing the error that do you forget to call public void setup(LocalActivityManager activityGroup)?

public class MainActivity extends FragmentActivity {
    private Resources res;
    private TabHost tabHost;

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

        // tabHost = getTabHost();
        TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);

            tabHost.setup();

        res = getResources();

        Intent intentContact = new Intent().setClass(this,
                tabOne_Activity.class);
        TabSpec tabSpecContact = tabHost.newTabSpec("Chat")
                .setIndicator("", res.getDrawable(R.drawable.ic_launcher))
                .setContent(intentContact);
        tabHost.addTab(tabSpecContact);

        Intent intentChat = new Intent().setClass(this, tabTwo_Activity.class);
        TabSpec tabSpecChat = tabHost.newTabSpec("Chat")
                .setIndicator("", res.getDrawable(R.drawable.ic_launcher))
                .setContent(intentChat);
        tabHost.addTab(tabSpecChat);

        Intent intentProfile = new Intent().setClass(this,
                tabThree_Activity.class);
        TabSpec tabSpecProfile = tabHost.newTabSpec("Chat")
                .setIndicator("", res.getDrawable(R.drawable.ic_launcher))
                .setContent(intentProfile);
        tabHost.addTab(tabSpecProfile);

        tabHost.setCurrentTab(2);


    }
}

解决方案

You are trying to use tabhost.For that you must extend TabActivity.

OR

Write the below code in onCreate():

LocalActivityManager mlam = new LocalActivityManager(this, false);
        mlam.dispatchCreate(savedInstanceState);
        // tabHost = getTabHost();
        //tabHost.setup();
        tabHost.setup(mlam);