其實,我一直重用我在我的片段,如以下幾種觀點:片段 - 我應該在onCreateView中重用視圖,我應該怎麼做?
private View mView = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
if (mView == null)
mView = inflater.inflate(R.layout.view);
return mView;
}
這工作,與viewpager等。現在,我開始使用我的簡單的活動片段,以及如果,且僅當,我的片段添加到堆棧中,這將失敗,因爲java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
所以我的問題是:
- 它是確定,如果我檢查父視圖,將其刪除並將其添加到新的父級?
- 或者我應該總是重新創建視圖並且永不重複使用它?如果是,爲什麼?
- 有沒有其他的觀點,重用視圖會失敗?
感謝您的解釋,這使我更清楚 – prom85