Tabhost在片段:你忘了叫“公共无效设置(localactivitymanager的ActivityGroup)” [英] Tabhost in Fragment: did you forget to call 'public void setup(localactivitymanager activitygroup)'

查看:149
本文介绍了Tabhost在片段:你忘了叫“公共无效设置(localactivitymanager的ActivityGroup)”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个Tabhost一个片段里,得到了异常
 你忘了打电话给公共无效设置(localactivitymanager的ActivityGroup)

I want to have a Tabhost inside a Fragment and got the Exception did you forget to call public void setup(localactivitymanager activitygroup)

下面我code:

布局:

<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:orientation="horizontal" />

        <FrameLayout
            android:id="@+id/realtabcontent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
    </LinearLayout>

</android.support.v4.app.FragmentTabHost>

片段:

public class TabsFragment extends SherlockFragment implements OnTabChangeListener{

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        this.contentView = inflater.inflate(R.layout.fragment_details, container, false);
        mTabHost = (FragmentTabHost) this.contentView.findViewById(android.R.id.tabhost);

        return this.contentView;
    }

@Override
    public void onResume() {

        super.onResume();

        mTabHost.setup(getSherlockActivity(),getChildFragmentManager());
        mTabHost.setOnTabChangedListener(this);

        // First Tab
        String s = getResources().getString(R.string.title_tab1);
        TabSpec spec = mTabHost.newTabSpec(s);
        Intent i = new Intent(getSherlockActivity(), FirstTab.class);
        spec.setIndicator(s);
        spec.setContent(i);
        mTabHost.addTab(spec);

 // Adding more tabs here
...

}

就像你所看到的,我已经叫设置。我有不知道为什么会抛出异常:(

Like you can see I've already called the setup. I've got no idea why the exception is thrown :(

希望有人可以帮助我。

Hopefully someone could help me.

THX!

推荐答案

要扩展Activity类,尽量延长TabActivity类

you are extending Activity class, try extending TabActivity class

如果你想使用Activity类,然后使用以下内容:

if you want to use the Activity class then use the following :

host = (TabHost) findViewById(R.id.tabhost); //here tabHost will be your Tabhost
LocalActivityManager mLocalActivityManager = new LocalActivityManager(mActivity, false);
mLocalActivityManager.dispatchCreate(state); // state will be bundle your activity state which you get in onCreate
tabHost.setup(mLocalActivityManager);

这篇关于Tabhost在片段:你忘了叫“公共无效设置(localactivitymanager的ActivityGroup)”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆