片段内的 Tabhost 不工作

Tabhost inside Fragment not working

//HappChat.java

public class HappChat extends Fragment {

TabHost tabhost;

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.chat_header, container, false);

    tabhost = (TabHost) rootView.findViewById(android.R.id.tabhost);

    tabhost.setup();

    TabSpec ts = tabhost.newTabSpec("Tab 1");
    ts.setIndicator("", getResources().getDrawable(R.drawable.tab_user));
    ts.setContent(new Intent(getActivity(), ChatFirstTab.class));
    tabhost.addTab(ts);

    TabSpec ts1 = tabhost.newTabSpec("Tab 2");
    ts1.setIndicator("", getResources().getDrawable(R.drawable.tab_chat));
    ts1.setContent(new Intent(getActivity(), ChatSecondTab.class));
    tabhost.addTab(ts1);

    for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
    {
        tabhost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#E8E8E8"));
    }
    tabhost.getTabWidget().setCurrentTab(0);
    tabhost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#FFFFFF"));

    tabhost.setOnTabChangedListener(new OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
            // TODO Auto-generated method stub
            for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
            {
                tabhost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#E8E8E8"));
            }

            tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(Color.parseColor("#FFFFFF"));
        }
    });

    return rootView;
  }
}

//ChatFirstTab.java

public class ChatFirstTab extends Fragment {

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.chat_first, container, false);

    return rootView;
  }
}

//ChatSecondTab.java

public class ChatSecondTab extends Fragment {

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.chat_first, container, false);

    return rootView;
  }
}

我的问题是,虽然 运行 上面的代码显示了下面描述的错误。

06-23 04:32:00.658: E/AndroidRuntime(12802): java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
06-23 04:32:00.658: E/AndroidRuntime(12802):    at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:754)
06-23 04:32:00.658: E/AndroidRuntime(12802):    at android.widget.TabHost.setCurrentTab(TabHost.java:420)
06-23 04:32:00.658: E/AndroidRuntime(12802):    at android.widget.TabHost.addTab(TabHost.java:247)
06-23 04:32:00.658: E/AndroidRuntime(12802):    at com.happwall.HappChat.onCreateView(HappChat.java:31)
06-23 04:32:00.658: E/AndroidRuntime(12802):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
etc...

如何解决这个错误。我尝试了很多并引用了更多链接,但没有成功。有什么方法可以解决这个错误吗

如有任何帮助,我们将不胜感激。

你试过看这个吗post

正在处理类似的问题。