我想在Fragment中有一个Tabhost并获得Exception
did you forget to call public void setup(localactivitymanager activitygroup)
这是我的代码:
布局:
<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
...
}
就像你可以看到我已经调用了设置。我不知道为什么抛出异常:(
希望有人可以帮助我。
THX!
答案 0 :(得分:0)
public void setup(LocalActivityManager activityGroup)
如果您正在使用setContent(android.content.Intent),则必须调用此方法,因为启动本地活动需要activityGroup。如果您扩展TabActivity,则会为您完成此操作。
Android Exception: Did you forget to call 'public void setup (LocalActivityManager activityGroup)'
答案 1 :(得分:0)
你以这样的方式喊出addTab:
select="format-number($Vha*$PulsMult,'0.###')"
正如你所看到的,你必须使用Fragment类(不是Activity),最后一个参数应该是bundle(不是intent)
答案 2 :(得分:0)
您正在扩展Activity类,尝试扩展TabActivity类
或
如果要使用Activity类,请使用以下命令:
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);