2015-06-21 29 views
2
  • 我試着去一個tabhost添加到我的應用程序,但我不能弄清楚爲什麼這個錯誤「無法化解的構造意圖」顯示的是,這裏是我的活動代碼:無法解析構造意圖

    public class SixthFragment extends Fragment { 
    public static final String TAG = "sixth"; 
    
    
    
    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container,  Bundle savedInstanceState) { 
    
    View view = inflater.inflate(R.layout.sixthfragment, container, false); 
    TabHost tabHost = (TabHost) view.findViewById(R.id.tabHost); 
    
    TabHost.TabSpec tab1 = tabHost.newTabSpec("First Tab"); 
    TabHost.TabSpec tab2 = tabHost.newTabSpec("Second Tab"); 
    TabHost.TabSpec tab3 = tabHost.newTabSpec("Third tab"); 
    
    // Set the Tab name and Activity 
    // that will be opened when particular Tab will be selected 
    tab1.setIndicator("Tab1"); 
    tab1.setContent(new Intent(this,MainActivity.class)); 
    
    tab2.setIndicator("Tab2"); 
    tab2.setContent(new Intent(this,Tab2Activity.class)); 
    
    tab3.setIndicator("Tab3"); 
    tab3.setContent(new Intent(this,Tab3Activity.class)); 
    
    /** Add the tabs to the TabHost to display. */ 
    tabHost.addTab(tab1); 
    tabHost.addTab(tab2); 
    tabHost.addTab(tab3); 
    
    
    return view; 
    
    
    } 
    
    
    @Override 
    public void onActivityCreated(Bundle savedInstanceState) { 
    super.onActivityCreated(savedInstanceState); 
    
    } 
    
    
    
    } 
    

    一些幫助會感謝你的時間。

+0

使用'getActivity()'而不是'this' – Blackbelt

回答

2

Intent構造函數,你要使用的第一個參數需要一個ContextFragment不是Context。使用getActivity()而不是this

相關問題