【问题标题】:Get the TabHost from Fragment Activity从 Fragment Activity 获取 TabHost
【发布时间】:2013-12-09 10:46:18
【问题描述】:

我有一个像这样扩展 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();

这给了我一个错误。

【问题讨论】:

    标签: android android-fragments tabs


    【解决方案1】:

    试试这个:

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

    【讨论】:

    • 确保您调用的是 android.R.id.tabHost,而不是 /*your-package-name*/.R.id.tabHost
    • 我正在使用 tabHost = (TabHost) findViewById(R.id.tabHost);但它不工作
    • 您是否使用 tabActivity 扩展了您的活动?
    猜你喜欢
    • 2012-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多