【发布时间】:2015-08-07 20:19:49
【问题描述】:
我正在使用本教程中的材料设计导航抽屉
http://www.androidhive.info/2015/04/android-getting-started-with-material-design/
,我试图从第一个片段重定向到另一个片段,但我的应用程序崩溃了,并显示错误,
错误
java.lang.IllegalArgumentException: No view found for id 0x7f0d0053 (info.androidhive.materialdesign:id/container_body) for fragment All_Products{41ca7008 #0 id=0x7f0d0053}
ShopFragment.java
rl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
All_Products tf = new All_Products();
Bundle bundle = new Bundle();
bundle.putString("catagory_name", "All");
tf.setArguments(bundle);
android.support.v4.app.FragmentManager fm = getFragmentManager();
android.support.v4.app.FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.container_body, tf);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null);
ft.commit();
}
});
activity_main
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
</LinearLayout>
<FrameLayout
android:id="@+id/container_body"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
<fragment
android:id="@+id/fragment_navigation_drawer"
android:name="info.androidhive.materialdesign.activity.FragmentDrawer"
android:layout_width="@dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer"
tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
【问题讨论】:
-
如果您从一个片段转到另一个片段,您应该使用 getChildFragmentManager() 吗?
-
添加包含片段的 xml 文件,可能是您没有放入 id 标签,或者您有重复/未充分分配的 ID
-
@sirFunkenstine 已经尝试过使用 getchildfragmentmanager..但还是同样的错误
-
@Hughzi 你可以在给定的链接中看到我的整个结构..
-
@Hughzi 查看我更新的问题和错误