0

I've got a question. I have a fragment, which inflates two other fragments (Fragment A is left, Fragment B is right) I want to hide Fragment A when the user changes the mode to portrait-mode. I added in the layout-port/xml a DrawerLayout and added the code for the NavigationDrawer in my Fragment, but it doesn't work. Does anyone have an idea, how to realize it?

Thanks :)

1 Answers1

0

I've solved the first problem with this code:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
     orientation = newConfig.orientation;
    switch (orientation) {
    case Configuration.ORIENTATION_LANDSCAPE:
        FragmentA fragmentleft = new FragmentA();
        FragmentB fragmentright = new FragmentB();
        FragmentTransaction transaction1 = getSupportFragmentManager()
                .beginTransaction();
        FragmentTransaction transaction2 = getSupportFragmentManager()
                .beginTransaction();

        transaction1.replace(R.id.framelayout_left, fragmentleft);
        transaction2.replace(R.id.framelayout_right, fragmentright);
        transaction1.commit();
        transaction2.commit();

        break;
    case Configuration.ORIENTATION_PORTRAIT:
        createNavigationDrawer();
        Log.d("TEST", "Portrait");


        break;

    }
}

But now I have the problem, that i have to inflate FragmentA in my ListView of the DrawerLayout:

<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/framelayout_right"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />


<ListView
    android:id="@+id/framelayout_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" />

But how can I do this? It doesn't work properly :( I had also tried to change the ListView to a FrameLayout and inflate the FragmentA within it, but it didn't work too:(

I would be very thankful, if somebody could help me :)