0

I'm having trouble with having 2 drawers on a DrawerLayout. I have 2 ListView in my layout, but only the right one (layout_gravity=start/left) opens. Doesn't matter which one I set to this gravity.

Is there something special that needs to be set in order to have the 2 working together? maybe in the manifest?

activity_main.xml

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

    <!-- The main content view -->

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

        <com.lablabla.homedestroyer.GameView
            android:id="@+id/gameView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

    <!-- Listview to display slider menu -->

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

    <!-- Right Drawer - Weapons -->

    <ListView
        android:id="@+id/right_drawer"
        android:layout_width="180dp"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:background="#111"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp" />

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

And referencing them in the Activity

MainActivity.java-

mPlanetTitles = getResources().getStringArray(R.array.planets_array);
mWeaponsTiltes = getResources().getStringArray(R.array.weapons_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mMenuDrawerList = (ListView) findViewById(R.id.left_drawer);
// Set the adapter for the list view
mMenuDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles));
// Set the list's click listener
mMenuDrawerList.setOnItemClickListener(new MenuDrawerItemClickListener());

mWeaponsDrawerList = (ListView) findViewById(R.id.right_drawer);
// Set the adapter for the list view
mWeaponsDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mWeaponsTiltes));
mWeaponsDrawerList.setOnItemClickListener(new WeaponsDrawerItemClickListener());

// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(menuDrawerListener);

Both findViewById calls for the ListViews works and returns non-null values

EDIT Code for the DrawerListener

private DrawerListener menuDrawerListener = new DrawerListener() {

    @Override
    public void onDrawerStateChanged(int arg0) {    

        Log.d("DrawerListener", "Changed");
    }

    @Override
    public void onDrawerSlide(View arg0, float arg1) {
        Log.d("DrawerListener", "Slided");
    }

    @Override
    public void onDrawerOpened(View arg0) {
        Log.d("DrawerListener", "Opened");
    }

    @Override
    public void onDrawerClosed(View arg0) {
        Log.d("DrawerListener", "Closed");

    }
};
La bla bla
  • 8,558
  • 13
  • 60
  • 109
  • You mean you can't even drag it open? – Mike M. Dec 10 '14 at 19:42
  • Yes, it acts as if the right drawer doesn't exists. It doesn't even trigger any events in the `DrawerListener` – La bla bla Dec 10 '14 at 19:46
  • 1
    Post the code for your DrawerListener. – Squonk Dec 10 '14 at 20:17
  • Have you tried opening it programmatically, for testing? I.e., `mDrawerLayout.openDrawer(Gravity.END)`? – Mike M. Dec 10 '14 at 20:23
  • @MikeM., Squonk, Edited., Tried it now, it dims the screen, the same way the back of the screen does when the left drawer opens, but nothing is shown except for this – La bla bla Dec 10 '14 at 20:46
  • Do you mean you got it open programmatically, or you got it drag-sliding now? Does it respond to list item click events when it's open? Is that ListView perhaps empty, and it's blending into the background? Also, what kind of View is your GameView? And, is there a reason you used exact measures for the DrawerLayout, instead of `match_parent`? I don't think that would cause a problem, but who knows, at this point. – Mike M. Dec 10 '14 at 20:57
  • It doesn't open, it only fades the background the same way an open drawer is. Still no luck on the drag-sliding open. It's not empty cause if I switch the `layout_gravity` between the drawers, the should-be-right drawer opens correctly from the left. GameView is a surface view which at the moment only draws (successfully) a single bitmap. Thanks for your help! – La bla bla Dec 10 '14 at 21:01
  • I would imagine the SurfaceView is causing the problem. Please temporarily remove it, and test your drawers. – Mike M. Dec 10 '14 at 21:31
  • Hi, It didn't work. I changed my view back to what it says on the Android tutorial of creating navigation drawers, removed the creation of my surface view, same problem. There might be something wrong with my whole navigation drawer, as this is not the 1st problem I'm having with it, see here http://stackoverflow.com/q/27283348/975959 – La bla bla Dec 10 '14 at 21:46
  • Is the `MeasureSpec.EXACTLY` error only happening in your IDE? If it's not a runtime error, then try running the app with `match_parent` values. – Mike M. Dec 10 '14 at 23:35
  • It is a runtime error. I saw people getting this only in the IDE, but I'm getting it in runtime, causes the whole app to crush. Following the Android tutorial exactly but still no go. Maybe something in the Manifest I missed? Minimum SDK version is 14 at the moment, target SDK 21 – La bla bla Dec 11 '14 at 09:22

0 Answers0