I am looking for a solution as to how I can set the text of username and email in the navigation drawer from a MainActivity referencing the IDs within another layout.
nav_header_main.xml
Below is code displaying the logged in user referencing the TextViews from the activity_main.xml however I need the "R.id." to reference the username and email TextViews inside the nav_header_main.xml to be able to display user's details in a navigation drawer header.
MainActivity.java
if(!SharedPrefManager.getInstance(this).isLoggedIn()){
finish();
startActivity(new Intent(this, LoginActivity.class));
}
textviewUsername = (TextView)findViewById(R.id.username);
textviewEmail = (TextView)findViewById(R.id.email);
/*
textviewUsername = (TextView)findViewById(R.id.textViewUsernameNav);
textViewEmail= (TextView)findViewById(R.id.textViewEmailNav); */
textviewEmail.setText(SharedPrefManager.getInstance(this).getEmail());
textviewUsername.setText(SharedPrefManager.getInstance(this).getUsername());
nav_header_xml
android:id="@+id/nav_header_main_id"
<TextView
android:id="@+id/textViewUsernameNav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:text="Username"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="@+id/textViewEmailNav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="username@email.com" />