android
how to replace the Android NavigationView HeaderView
I have two different header xml layouts and want to switch between them programmatically. My problem is that the old layout is not replaced by the new but instead I end up with two header layouts. I read many Answers1 , Answer2 but it does not work. Here“s what i try: and if i run this code 3 times I have 3 headers instead of replacing the header layout. I think I must delete the navigate.getHeaderView(0) first but how? NavigationView navigate = (NavigationView) findViewById(R.id.navigation_view); navigate.getMenu().clear(); navigate.inflateMenu(R.menu.menu_navigation_exit); navigate.inflateHeaderView(R.layout.navigation_view_header_exit); View header = navigate.getHeaderView(0); streetViewImage = (ImageView) header.findViewById(R.id.street_view_image); streetViewImage.set.... ...
You need to save the reference of the header view and then remove it when you want to replace it with something else. navigate.removeHeaderView(previousHeaderView)
Related Links
Android camera takePicture() method execution time
A Thread in a service/activity
Error in gallery activity imageLoader
Get list of friends' names and IDs fast
Problem with the display of custom listview (webview in my listview)
parsing json feed and save the details in shared preference? [closed]
Dynamically change font size in Android
Android multicolumn ListView
Using OnItemClickListener on ListView inside TabActivity
Should I use separate locationManager for GPS and Network Provider?
android: ViewPager and HorizontalScrollVIew
Android EPUBLIB read/load content
Stop Google maps navigation programmatically
Android: listview crashes
how to call a java class from OnItemClick()?
android: Determine security type of wifi networks in range (without connecting to them)