1. Are you ready for the Galaxy S20? Here is everything we know so far!

DataBinding with Navigation Drawer

Discussion in 'Android Development' started by frappydan, May 28, 2021.

  1. frappydan

    frappydan Lurker
    Thread Starter

    Started using DataBinding in my app. Was moving right along until I tried to update my main app (which is built inside of navigationDrawer. I cut out all of the controls as they are not an issue and binding lets me access them just fine. The problem is that the nav_header_main contains a lot of controls that I need to access as well and I currently use findViewByID to get them. I believe the databinding is binding around the activity but won't let me access anything that's just inside of a layout (like the nav_header_main. Haven't found any good articles on how to do this so far so I thought I'd ask. Was also curious if having all of my views inside the nav_header_main was a bad idea. Don't know how else to get content into the drawer without using a fragment. As you can tell, I'm a java novice. Normally a C# programmer but decided to migrate to android programming.

    This is my main app (trimmed to save space)

    Code (Java):
    2. <layout>
    3. <androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    4.     xmlns:app="http://schemas.android.com/apk/res-auto"
    5.     xmlns:tools="http://schemas.android.com/tools"
    6.     android:id="@+id/drawerLayout2"
    7.     android:layout_width="match_parent"
    8.     android:layout_height="match_parent"
    9.     android:background="@color/white"
    10.     android:padding="3dp">
    12.     <androidx.constraintlayout.widget.ConstraintLayout
    13.         android:layout_width="match_parent"
    14.         android:layout_height="wrap_content"
    15.         android:background="#FFFFFF"
    16.         android:padding="2dp">
    18.         Textviews, buttons, etc... removed so this would fit.
    20.     </androidx.constraintlayout.widget.ConstraintLayout>
    22.     <com.google.android.material.navigation.NavigationView
    23.         android:id="@+id/navigationView2"
    24.         android:layout_width="wrap_content"
    25.         android:layout_height="match_parent"
    26.         android:layout_gravity="start"
    27.         android:fitsSystemWindows="true"
    28.         app:headerLayout="@layout/nav_header_main" >
    30.     </com.google.android.material.navigation.NavigationView>
    32. </androidx.drawerlayout.widget.DrawerLayout>
    33. </layout>

    1. Download the Forums for Android™ app!



Share This Page