2017-09-05 5 views
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입니다 시작 :

case R.id.cambiarVista: 
       FragmentTransaction t = getSupportFragmentManager().beginTransaction(); 
       t.replace(R.id.calendar1, new ListaEntrenamientos()); 
       t.addToBackStack(null); 
       t.commit(); 

이 조각을 : 내가 버튼을 클릭하면

FragmentTransaction t = getSupportFragmentManager().beginTransaction(); 
    t.replace(R.id.calendar1, caldroidFragment); 
    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> 

그러나이 버튼을 클릭하면 응용 프로그램이 충돌하고 작동합니다. 어떤 메시지도 보여주지 마라.

내 오류는 무엇입니까? 나는 다른 옵션으로 여러 번 시도하지만 동일합니다.

감사합니다.

+0

Logcat에 메시지가 표시됩니다. –

+0

그런데'DrawerLayout은 최상위 컨테이너 역할을합니다. '(문서). 그리고 오리엔테이션이 없습니다 ... xml을 다시 시도하십시오 –

+2

logcat에서'No Filters'를 선택하고 logcat을 게시하십시오. –

답변

0

calendar1FrameLayout이고 fragment이 아니기 때문에 FragmentManager이 충돌합니다. calendar1ListaEntrenamientosViews을 만들거나 둘 다 Fragments으로 만드십시오. 둘 중 하나가 작동합니다. 나는 그들에게 Views (LinearLayout/FrameLayout)을 만들 것을 권하고, VisibilityGONE으로 변경하면 화면에 나타나지 않을 것입니다.