2013-02-20 90 views
0

我想大家都知道在eclipse中創建項目時選擇「master detail flow」時創建的項目。 enter image description here片段活動崩潰,好像它是嵌套的片段

Theres佈局爲左側,右側爲two_pane佈局,片段和Framelayout爲片段容器。這工作正常。

現在我有一個'主'活動A與viewpager,片段等,我用Callback從一個片段調用活動。從那個活動開始,我開始一個新的活動B.那個活動B的建立與我剛剛提到的來自eclipse的示例活動完全相同。

現在我有一個與

ERROR/AndroidRuntime(8105): Caused by: java.lang.IllegalArgumentException: Binary XML file line #57: Duplicate id 0x7f080024, tag null, or parent id 0x0 with another fragment for FragmentNumber3 

應用程序崩潰。當我更換另一個FrameLayout裏的two_pane佈局片段中的問題,它不會崩潰。 這個問題對於嵌套片段是典型的,但我沒有嵌套片段,對吧?我有一個活動B,在那一點上,與我的活動A沒有任何關係。

這裏有什麼問題?

編輯:這是我的活動B:

公共類SucheActivity擴展FragmentActivity實現 SearchboxFragment.SearchboxListener {

private boolean mTwoPane; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.searchbox); 

    getActionBar().setDisplayHomeAsUpEnabled(true); 

    if (findViewById(R.id.searchresult_container) != null) { 

     mTwoPane = true; 
    } 
} 
} 

和多數民衆的活動two_pane佈局,搜索框應該離開了, searchresults right:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginLeft="16dp" 
    android:layout_marginRight="16dp" 
    android:baselineAligned="false" 
    android:divider="?android:attr/dividerHorizontal" 
    android:orientation="horizontal" 
    android:showDividers="middle" > 

    <fragment 
     android:id="@+id/searchbox_fragment" 
     android:name="com.example.layouttest.SearchboxFragment" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1"/> 

    <FrameLayout 
     android:id="@+id/searchresult_container" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="3" /> 

</LinearLayout> 

繼承人SearchboxFragment類:

public class SearchboxFragment extends Fragment { 

SearchboxListener mCallback; 
View v; 

public interface SearchboxListener { 
    public void onSearchStarted(); 
} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 

    v = inflater.inflate(R.layout.searchbox, container, false); 


    return v; 
} 
} 

的searchresultfragment:

public class SearchResultFragment extends Fragment { 


public SearchResultFragment() { 
} 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 

    return inflater.inflate(R.layout.searchresult, container, false); 
} 

@Override 
public void onViewCreated(View view, Bundle savedInstanceState) { 

    super.onViewCreated(view, savedInstanceState); 

} 

} 

而且在res /中refs.xml價值觀大:

<resources> 

    <item name="searchbox" type="layout">@layout/haussuche_twopane</item> 

</resources> 
+0

你確定沒有2個相同ID的veiws? – 2013-02-20 09:58:00

+0

我覺得是的。我添加了一些代碼。 – FWeigl 2013-02-20 10:02:38

+0

從錯誤它似乎像兩個視圖有相同的ID和正在崩潰彼此可能試圖訪問第一個活動視圖不可用只是確保所有的ID都是唯一的 – 2013-02-20 10:06:42

回答

0

好了,這是我發現:

我無法將我的Activity的佈局設置爲searchbox.xml(並使用two_pane.xml將其設置爲refs.xml中的別名),並將SearchboxFragment的Layout設置爲searchbox。 XML。

我認爲searchbox.xml從來沒有在雙窗格模式下顯示,我可以在別處安全地設置它,但這是錯誤的。

我所做的是複製該佈局,並使用searchbox_onepane.xml和searchbox_twopane.xml。