DataBinding with Navigation Drawer

frappydan

Lurker
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)

Java:
<layout>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawerLayout2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:padding="3dp">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        android:padding="2dp">

        Textviews, buttons, etc... removed so this would fit.

    </androidx.constraintlayout.widget.ConstraintLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/navigationView2"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main" >

    </com.google.android.material.navigation.NavigationView>

</androidx.drawerlayout.widget.DrawerLayout>
</layout>
 
Top