0

我得到「指定的子項已經有父項,必須先調用子項的父項的removeView()。在我的onCreateView方法被調用後直接拋出。拋出的異常:你必須調用removeView上的fragment創建

InkomendFragment

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     View v = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_inkomend, 
       container); 
     return v; 
    } 
+1

你也可以這樣做:'視圖V = LayoutInflater.from(getActivity())膨脹(R.layout.fragment_inkomend, 容器,假);' –

回答

2

我花了很長一段時間才能找出

正確的語法:

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    View v = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_inkomend, 
      null); 
    return v; 
} 

顯然你不需要放任何東西在參數「根」。

2

試試這個..

下面也是正確的語法

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    View v = inflater.inflate(R.layout.fragment_inkomend, container, false); 
    return v; 
} 
+0

你說得對。什麼會更好?它似乎不需要容器ViewGroup,對吧? –

+0

@BartBurg和'onCreateView'構造函數中的'LayoutInflater'中的inflater相同。無需外部充氣。 – Hariharan

相關問題