0

I am using a custom list view to display data in my app, Then i tried to add navigation drawer

Clicks on drawer layout doesnt work. It end up opening the custom list view as it is behind the drawer list view. Drawer list view never gets focus, Even when the drawer is opened

Below is my main activity xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:focusable="true"/>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:focusableInTouchMode="true"
android:focusable="true"
android:descendantFocusability="blocksDescendants"/>
</android.support.v4.widget.DrawerLayout>
<ListView
android:id="@+id/listScreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="7dp">
</ListView>
</RelativeLayout>

2 Answers2

8

Use this way :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<include layout="@layout/actionbar" />

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <!-- The main content view -->

    <include layout="@layout/activity_main" />

    <!-- The navigation drawer -->

    <include layout="@layout/drawer_layout_right" />

    <include layout="@layout/drawer_layout_left" />
</android.support.v4.widget.DrawerLayout>

drawer_layout_right.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:orientation="horizontal" >

<ListView
    android:id="@+id/lv1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none" />

</LinearLayout>

drawer_layout_left.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:orientation="vertical" >

<ListView
    android:id="@+id/lv2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none" />

</LinearLayout>
RuNo280
  • 573
  • 4
  • 27
  • I use this approach as well .. whats happening is my main activity has list view, and it has on item click listener ....my navigation drawer has list view which also has on item click listener ....when i open the drawer ....drawer list over laps with main list and i end up clicking the main activity list ......Drawer list never gets the focus – user3710994 Jun 06 '14 at 02:22
  • You were right.. it Worked for me finally ...I did not implement as you told, I corrected it later on ...her is my code – user3710994 Jun 06 '14 at 03:08
0
<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" >

 <include layout="@layout/activity_main" />

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusableInTouchMode="true"
    android:focusable="true"/>
<ListView
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="#111"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"/>


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