I have a image and a text in my Header layout which is included through android.support.design.widget.NavigationView. The picture will be user's profile picture and text will be name which I'll get from Session Manager Class.
How can I access and edit the text and image programmatically, since it's only included in the definition of NavigationView.
Here's the code:
<android.support.design.widget.NavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:id="@+id/shitstuff"
app:itemTextColor="@color/grey"
app:menu="@menu/drawermenu"
app:headerLayout="@layout/headerlayout"
app:itemIconTint="@color/colorPrimary"
android:layout_marginTop="0dp"
/>
And in activity class:
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mNavigationView = (NavigationView) findViewById(R.id.shitstuff) ;
/**
* Lets inflate the very first fragment
* Here , we are inflating the TabFragment as the first Fragment
*/
mFragmentManager = getSupportFragmentManager();
mFragmentTransaction = mFragmentManager.beginTransaction();
mFragmentTransaction.replace(R.id.containerView,new helpfragment()).commit();
/**
* Setup click events on the Navigation View Items.
*/
mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
mDrawerLayout.closeDrawers();
if (menuItem.getItemId() == R.id.nav_item_home) {
Intent i = new Intent(help.this, home.class);
startActivity(i);
}
if (menuItem.getItemId() == R.id.nav_item_tenant) {
Intent i = new Intent(help.this, rentertabview.class);
startActivity(i);
}
if (menuItem.getItemId() == R.id.nav_item_profile) {
Intent i = new Intent(help.this, profile.class);
startActivity(i);
}
if (menuItem.getItemId() == R.id.nav_item_owner) {
Intent i = new Intent(help.this, ownertabview.class);
startActivity(i);
}
if (menuItem.getItemId() == R.id.nav_item_services) {
Intent i = new Intent(help.this, services.class);
startActivity(i);
}
return false;
}
});
/**
* Setup Drawer Toggle of the Toolbar
*/
android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout, toolbar,R.string.app_name,
R.string.app_name);
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
Please explain in details. Will be really thankful to you.