小编Mr.*_*.P.的帖子

带有嵌套/子片段的Android Backstack

我对嵌套片段的堆栈方式有一个问题,并且非常感谢所提供的任何帮助.

我有片段A和片段B.片段A包含另一个片段(ButtonFragment).在活动的onCreate中,我加载片段A,而不是切换到片段B.当我回到片段A(从后台堆栈中)时,我得到以下错误.

异常调度完成信号.

E/MessageQueue-JNI(6330):MessageQueue回调中的异常:handleReceiveCallback

E/MessageQueue-JNI(6330):android.view.InflateException:二进制XML文件行#16:错误膨胀类片段

...

引起:java.lang.IllegalArgumentException:二进制XML文件行16:重复id 0x7f080000,标记null或父id 0x0与另一个片段com.example.fragmentnavigation.MainActivity $ ButtonFragment

没有子片段导航工作.也许我必须添加一些ChildFragmentManager处理,但我不知道在哪里和哪里.我希望你能帮助我.

MainLayout

<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:orientation="vertical" >

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/app_name" />

<FrameLayout 
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context="com.example.fragmentnavigation.MainActivity"
    tools:ignore="MergeRootFrame" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

片段布局

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.fragmentnavigation.MainActivity$FragmentA" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <fragment 
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:name="com.example.fragmentnavigation.MainActivity$ButtonFragment"/> 

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

MainAcitivity

public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new …
Run Code Online (Sandbox Code Playgroud)

navigation android android-fragments android-nested-fragment fragment-backstack

3
推荐指数
1
解决办法
711
查看次数