0
我越来越疯狂。我想动态地用另一个片段替换一个片段。更改片段动态崩溃应用程序
我在活动定义mainLayout这样的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/EstiloBase"
android:baselineAligned="false"
android:orientation="vertical">
<include
android:id="@+id/tool_bar_dashboard"
layout="@layout/toolbar" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal">
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="200dp"
android:layout_height="match_parent"
android:orientation="horizontal">
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
<FrameLayout
android:id="@+id/calendar1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
我想更换产品的FrameLayout里。
在启动的FrameLayout是raplce这个片段及其一切ok:
FragmentTransaction t = getSupportFragmentManager().beginTransaction();
t.replace(R.id.calendar1, caldroidFragment);
t.commit();
然后,当我在一个按钮,单击它会通过这个替换:
case R.id.cambiarVista:
FragmentTransaction t = getSupportFragmentManager().beginTransaction();
t.replace(R.id.calendar1, new ListaEntrenamientos());
t.addToBackStack(null);
t.commit();
此片段它定义如下:
<FrameLayout 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"
tools:context="tfg.marcos.coachtrain.views.fragments.ListaEntrenamientos">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>
但是,当我点击该按钮,应用程序崩溃,它会不给我看任何消息。
我的错误是什么?我用其他选项尝试了很多次,但都是一样的。
谢谢。
Logcat应该显示一条消息 –
顺便说一句,'DrawerLayout作为一个顶级容器'(文档)。它没有方向...尝试再次做xml –
在logcat中选择'No Filters'并发布你的logcat。 –