2015-01-18 1 views
0

팽창 할 수 없습니다서랍 조각의 컨테이너가 null 그래서 나는 다음과 같은 한 그것을

activity_main.xml가 : 단지 목록보기보다 더 서랍을 잡아 FrameLayout이와 조각이 포함

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity"> 

    <FrameLayout android:id="@+id/container" android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <fragment android:id="@+id/navigation_drawer" 
     android:layout_width="@dimen/navigation_drawer_width" android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:name="com.example.example.drawer.DrawerFragment" 
     tools:layout="@layout/drawer_fragment" /> 

</android.support.v4.widget.DrawerLayout> 

<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:paddingLeft="16dp" 
    android:paddingRight="16dp" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/profilePhoto" 
     android:layout_width="match_parent" 
     android:contentDescription="@null" 
     android:layout_height="128dp" /> 

    <ListView 
     android:id="@+id/lvOptions" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="3dp" 
     android:background="#cccc" 
     tools:context=".NavigationDrawerFragment" /> 

</LinearLayout> 

MainActivity의 setContentView(R.layout.activity_main); 실행리스트 뷰의 상부에 화상과

drawer_fragment.xml, 또한 카세트 단편 (A)의 실행 onCreateView utomatically하지만 컨테이너는 null입니다. 나는 다음을 수행하십시오

View rootView = inflater.inflate(R.layout.drawer_fragment, container, false); 
mDrawerLayout = (DrawerLayout) rootView.findViewById(R.id.drawer_layout); 

하지만 mDrawerLayout가 null 그 후, 나는 용기가, 내가 무엇을 놓치고 널이기 때문에 것 같아요?

+0

활동에서 펼쳐지는 서랍 레이아웃에는 내용 프레임과 서랍 (조각)이 있습니다. 따라서 서랍 레이아웃을 찾고 있지 않은 조각에서는 목록보기를 찾고 있습니다. 그래, 처음 엔 혼란 스럽다. –

답변

0

레이아웃 R.layout.drawer_fragment에는 R.id.drawer_layout ID가 포함 된보기가 없으므로 예 mDrawerLayout은 항상 null입니다. ID가 drawer_layout 인보기에 액세스하려면 활동에서 전화해야합니다.