0

在logcat的錯誤:E/FragmentManager(7158): No view found for id 0x7f05000d (com.mybiz.mygame:id/fragment_container) for fragment MainMenuFragment{4052d780 #0 id=0x7f05000d}Android的碎片錯誤:沒有查看發現ID

確定這裏是如何應用程序設置:

兩個瓦爾創建:

private static View oGoogleGamesView ; 
private static RelativeLayout oViewGroup ; 

然後在的onCreate:

oViewGroup = new RelativeLayout (this) ; 
setContentView (oViewGroup) ; 

LayoutInflater inflater = (LayoutInflater)this.getSystemService (Context.LAYOUT_INFLATER_SERVICE) ;  
oGoogleGamesView  = inflater.inflate (R.layout.ggmain, oViewGroup, false) ; 

然後我試圖說明的片段:

// create fragments 
mMainMenuFragment = new MainMenuFragment(); 

// listen to fragment events 
mMainMenuFragment.setListener(this); 

// add initial fragment (welcome fragment) 
getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, 
     mMainMenuFragment).commit(); 

在這裏,它崩潰的錯誤在上面。下面是XML文件:

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

我能做些什麼來顯示片段沒有崩潰?

回答

1

您可以設置您的應用程序以oViewGroup:

setContentView (oViewGroup) ; 

然後你誇大另一種觀點認爲,讓它叼着:

oGoogleGamesView  = inflater.inflate (R.layout.ggmain, oViewGroup, false) ; 

要真正有oGoogleGamesView在您的應用程序佈局,你必須將其添加到當前視圖,然後纔可以參考其中包含的ID:

oViewGroup.addView(oGoogleGamesView, LayoutParams); 
1

嘗試在onCreate方法 的setContentView此 (R.layout.yourLayout); 其中yourLayout是包含frameLayout的xml文件,您已將其放入您的問題中。

+0

感謝您e回覆,但是這樣做會破壞我的應用程序,我需要將我的ContentView設置爲oViewGroup。 – Selzier

+0

可以請你發佈MainMenuFragment的代碼 – 2013-10-18 05:36:48