I have a NavigationView in a Drawer Layout which contains a HeaderView followed by a Menu (as given in AndroidStudio's Navigation Drawer Activity's template). My Header contains an Image and couple of TextViews in a LinearLayout. I want to edit of one of the TextViews in the header from SharedPreferences. I use following function to do so
public void navUpdate()
{
navigationView=(NavigationView)findViewById(R.id.nav_view);
linearLayout=(LinearLayout) LayoutInflater.from(this).inflate(R.layout.nav_header_main, null);
textView_nname=(TextView)linearLayout.findViewById(R.id.textView_nname);
String name=sharedPreferences.getString("name","Your Name");
textView_nname.setText(name);
navigationView.removeHeaderView(linearLayout);
navigationView.addHeaderView(linearLayout);
}
The problem is , though I've added the line
navigationView.removeHeaderView(linearLayout);
my previous headerview is still visible above the new one. And previous one is not updated. I read about the method navigationview.getHeaderAt() in many answers but believe me, that method is not available.
Is there any solution for this problem, if not is there any other way to do so?