我有一個片段SearchPageFragment
(表示在平板的主視圖),其本身包含在其內部的兩個片段:切換定向誤差:片段錯誤 - 重複ID,標籤,或父ID爲0x0
<fragment android:name="com.test.fragments.SearchFormFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:id="@+id/searchFormFragment"
android:tag="searchFormFragmentTag">
<!-- Preview: [email protected]/fragment_search_form -->
</fragment>
<fragment android:name="com.test.fragments.SearchResultsFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/searchResultsFragment">
<!-- Preview: [email protected]/fragment_search_results -->
</fragment>
一切工作正常 - 頁面加載和一切工作正常...直到你改變方向。當你出現下列錯誤:
java.lang.IllegalArgumentException: Binary XML file line #10: Duplicate id 0x7f08001f, tag searchFormFragmentTag, or parent id 0x0 with another fragment for com.test.fragments.SearchFormFragment
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:262)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
下面是當您切換方向的調用序列:
SearchPageFragment(4911): Creating...
SearchPageFragment(4911): Inflating...
SearchFormFragment(4911): Creating...
SearchFormFragment(4911): Inflating...
SearchResultsFragment(4911): Creating...
SearchResultsFragment(4911): Inflating...
// Change Orientation
SearchPageFragment(4911): Pausing...
SearchFormFragment(4911): Pausing...
SearchResultsFragment(4911): Pausing...
SearchPageFragment(4911): Destroying...
SearchFormFragment(4911): Destroying...
SearchResultsFragment(4911): Destroying...
// All Seems Normal - But...
SearchPageFragment(4911): Creating...
SearchPageFragment(4911): Creating...
SearchPageFragment(4911): Inflating...
SearchFormFragment(4911): Creating...
SearchFormFragment(4911): Inflating...
SearchResultsFragment(4911): Creating...
SearchResultsFragment(4911): Inflating...
SearchPageFragment(4911): Inflating...
// SearchPageFragment has started twice and crashes when the second one inflates a ***unique*** component
AndroidRuntime(4911): Shutting down VM
有誰知道爲什麼我的容器碎片將與方向的變化被稱爲兩次?
把一個完整的答案。這並沒有說什麼。 –
對不起Sterling,我已經更新了我的答案,以便更加簡潔。希望能幫助到你。 – Graeme
謝謝!現在好多了。正確的答案,但現在更容易理解。 –