从片段活动中获取TabHost

时间:2013-12-09 10:46:19

标签: android android-fragments tabs

我有一个像这样扩展Fragment的类:

public class Fragment_Coupons extends Fragment {
    TabHost tabHost;
    TabHost.TabSpec spec;

    public Fragment_Coupons() {
    }

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

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

        return rootView;
    }
}

这个XML文件是:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

</TabHost>

现在我想得到

tabHost = getTabHost();

这给了我一个错误。

1 个答案:

答案 0 :(得分:0)

试试这个:

tabHost = (TabHost) findViewById(R.id.tabHost);
    tabHost.setup();