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)

Categories

HOME
nunit
solaris
can
database-normalization
cublas
scripting
pyqt4
settings
bing-maps
distribution
siddhi
mod-security
windows-ce
stellar.js
onedrive-api
enterprise-architect
modbus-tcp
jmp
blade
inno-download-plugin
object-storage
flask-sqlalchemy
ckfinder
syntax-highlighting
appirater
ceylon
corenlp-server
postback
kudu
database-comparison
simplecv
hreflang
joomla2.5
reactivekit
tex
apriori
importerror
serde
amq
context-sensitive-grammar
truezip
opengl-4
filehandle
mouseleave
rocks
omxplayer
spring-cloud-feign
burrows-wheeler-transform
beamer
simevents
udpclient
respondcms
nupic
nio2
realsense
vhosts
dynatree
sciruby
java-money
iced-coffeescript
node-serialport
entry-point
mintty
draw2d-js
android-framework
sbcl
asdf
kaleidoscope
failing-tests
luabind
silent
scrollbars
duplex
web-application-project
movieplayer

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile