2013-02-20 116 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。