Question

Here is the xml schema for my navigation drawer_main... i have to place user image in upper listview and other data via 2nd listview just like soundcloud. but i get 2nd listview in navigation drawer button and by moving edge i get first drawer.. help me to combine both XML code

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

    <FrameLayout
        android:id="@+id/content_frame"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ListView
        android:id="@+id/linerlayout_drawer"
        android:layout_height="match_parent"
        android:layout_width="240dp"
        android:layout_gravity="start"
        android:background="@color/white"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:layout_weight="1"/>

    <ListView
        android:id="@+id/listview_drawer"
        android:layout_height="match_parent"
        android:layout_width="240dp"
        android:layout_gravity="start"
        android:background="@color/white"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:layout_weight="1" />

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

Errors if i wrap them in linear layout

04-08 21:08:36.605: E/AndroidRuntime(9373): FATAL EXCEPTION: main
04-08 21:08:36.605: E/AndroidRuntime(9373): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ZDevelopers.Workmania/com.ZDevelopers.Workmania.MainActivity}: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
04-08 21:08:36.605: E/AndroidRuntime(9373):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
04-08 21:08:36.605: E/AndroidRuntime(9373):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
04-08 21:08:36.605: E/AndroidRuntime(9373):     at android.app.ActivityThread.access$700(ActivityThread.java:159)
04-08 21:08:36.605: E/AndroidRuntime(9373):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
04-08 21:08:36.605: E/AndroidRuntime(9373):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-08 21:08:36.605: E/AndroidRuntime(9373):     at android.os.Looper.loop(Looper.java:176)
04-08 21:08:36.605: E/AndroidRuntime(9373):     at android.app.ActivityThread.main(ActivityThread.java:5419)
04-08 21:08:36.605: E/AndroidRuntime(9373):     at java.lang.reflect.Method.invokeNative(Native Method)
04-08 21:08:36.605: E/AndroidRuntime(9373):     at java.lang.reflect.Method.invoke(Method.java:525)
04-08 21:08:36.605: E/AndroidRuntime(9373):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
04-08 21:08:36.605: E/AndroidRuntime(9373):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
04-08 21:08:36.605: E/AndroidRuntime(9373):     at dalvik.system.NativeStart.main(Native Method)
04-08 21:08:36.605: E/AndroidRuntime(9373): Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
04-08 21:08:36.605: E/AndroidRuntime(9373):     at android.support.v4.widget.DrawerLayout.isDrawerView(DrawerLayout.java:857)
04-08 21:08:36.605: E/AndroidRuntime(9373):     at android.support.v4.widget.DrawerLayout.closeDrawer(DrawerLayout.java:1058)
04-08 21:08:36.605: E/AndroidRuntime(9373):     at com.ZDevelopers.Workmania.MainActivity.selectItem(MainActivity.java:203)
04-08 21:08:36.605: E/AndroidRuntime(9373):     at com.ZDevelopers.Workmania.MainActivity.onCreate(MainActivity.java:142)
04-08 21:08:36.605: E/AndroidRuntime(9373):     at android.app.Activity.performCreate(Activity.java:5372)
04-08 21:08:36.605: E/AndroidRuntime(9373):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
04-08 21:08:36.605: E/AndroidRuntime(9373):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
04-08 21:08:36.605: E/AndroidRuntime(9373):     ... 11 more
Was it helpful?

Solution

@Zain wrap both your Listviews into a LinearLayout.

Like so:-

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

    <FrameLayout
        android:id="@+id/content_frame"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
<LinearLayout
        android:id="@+id/mainLinearLayout"
 android:layout_width="match_parent"
        android:layout_height="match_parent">

    <ListView
        android:id="@+id/linerlayout_drawer"
        android:layout_height="match_parent"
        android:layout_width="240dp"
        android:layout_gravity="start"
        android:background="@color/white"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:layout_weight="1"/>

    <ListView
        android:id="@+id/listview_drawer"
        android:layout_height="match_parent"
        android:layout_width="240dp"
        android:layout_gravity="start"
        android:background="@color/white"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:layout_weight="1" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>

Then change your

mDrawerLayout.isDrawerOpen(mainLinearLayout);

and

mDrawerLayout.closeDrawer(mainLinearLayout);

OTHER TIPS

I had a similar situation wherein I had to use a TextView along with 2 ListView inside the navigation drawer. The above solution helped me but I had to modify it as

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

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

    <LinearLayout
        android:id="@+id/ll_main_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tv_main"
            android:layout_width="240dp"
            android:layout_height="wrap_content"
            android:background="@color/list_background"
            android:gravity="center_vertical"
            android:paddingRight="40dp"
            android:text="@string/nav_cat_main"
            android:textColor="@color/list_item_title" />


        <ListView
            android:id="@+id/lv_slidermenu"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/list_background"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="1dp"
            android:listSelector="@drawable/list_selector" />

        <ListView
            android:id="@+id/lv_gallery"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/list_background"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="1dp"
            android:listSelector="@drawable/list_selector" />

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

As can be seen I had to the linear layout with the layout_gravity="start", and remove the same property from the inner views.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top