0

I created drawer menu: drawer menu. As you can see, I managed to show the drawer perfectly, but when I include the activity_main.xml it doesn't get the data (variables & placeholder)

my main_activity.xml: how it looks, TextView should be numbers and placeholder not getting any data so... drawer_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
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:openDrawer="end"
>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    <include
        layout="@layout/activity_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

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

   <android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/drawer_menu" />
   </android.support.v4.widget.DrawerLayout>

I need to show the data and still use the drawer... Is it possible? And if you need more information, just ask, I will provide

EDIT: I need to pass the information from MainActivity.class (connected to activity_main.xml) to Drawer_layout.class? (connected to drawer_layout.xml)

morkuk
  • 25
  • 6

1 Answers1

0

Nevermind guys, I managed to do this on my own. If anyone else has this problem: the include tag yes, it doesn't show or uses your activity (in my case, MainActivity.class), so what I did was to change activity_main.xml from RelativeLayout to DrawerLayout, no need in seperate layer. as you can see:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:background="@color/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/mainactivity"
android:paddingLeft="@dimen/mainactivity"
android:paddingRight="@dimen/mainactivity"
android:paddingTop="@dimen/mainactivity"
android:fitsSystemWindows="true"
tools:openDrawer="end"
tools:context=".MainActivity">

<!-- app code -->
<LinearLayout...>

 <!-- navigation drawer --> 
<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    app:menu="@menu/navigation_menu"
    android:layout_gravity="end"
    android:fitsSystemWindows="true"
    ads:headerLayout="@layout/navigation_header"
    >

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

it works perfectly if you have an existing project and you need to add navigation drawer. do the whole thing manually, it's better than the wizard.

then in MainActivity.class I refer the Navigation as usual

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_info) {

        startActivity(aboutact);

    } else if (id == R.id.nav_appinfo) {

        startActivity(appinfact);

    } else if (id == R.id.nav_contact) {

        startActivity(contactact);

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.activity_main);
    drawer.closeDrawer(GravityCompat.END);
    return true;
}

of course you still need navigation_menu.xml in menu pacakge...

and I prefer not to use actionBar as you can see, no toolbar, nothing. So I started the drawer from a button click:

mDrawerLayout = (DrawerLayout) findViewById(R.id.activity_main);
  hamburgerbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDrawerLayout.openDrawer(GravityCompat.END);

            }
        });

greetings.

morkuk
  • 25
  • 6