Tabhost error in getting in to my activity

删除回忆录丶 提交于 2019-12-20 07:47:12

问题


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);


    }
}

回答1:


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); 


来源:https://stackoverflow.com/questions/28360054/tabhost-error-in-getting-in-to-my-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!