2013-12-09 94 views
0

我有一个ClassThat扩展片段是这样的...从片段活动中获取TabHost?

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(); 

这是给我错误...需要帮助尽快。

回答

0

试试这个:

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

使其确保您呼叫android.R.id.tabHost,不/*your-package-name*/.R.id.tabHost我使用 –

+0

tabHost = (TabHost)findViewById(R.id.tabHost);但它不起作用 – NRahman

+0

您是否使用tabActivity扩展了您的活动? –