android - Fix Navigation Drawer Title change on orientation change? -


when orientation changed on app, title in action bar changes title of fragment selected in nav drawer title of app.

the navigation drawer example app retains it's title on orientation change because it's fragment subclass of main activity, , has line of code

getactivity().settitle(planet); 

now i'm bit newbie wouldn't know how retain title, , implement code, can guys help?

just in case of wanna see, here subclass planetfragment

public static class planetfragment extends fragment {     public static final string arg_planet_number = "planet_number";      public planetfragment() {         // empty constructor required fragment subclasses     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {         view rootview = inflater.inflate(r.layout.fragment_planet, container, false);         int = getarguments().getint(arg_planet_number);         string planet = getresources().getstringarray(r.array.planets_array)[i];          int imageid = getresources().getidentifier(planet.tolowercase(locale.getdefault()),                         "drawable", getactivity().getpackagename());         ((imageview) rootview.findviewbyid(r.id.image)).setimageresource(imageid);         getactivity().settitle(planet);         return rootview;     } } 

from navigation drawer example app, here did :

  • on onsaveinstancestate() of activity :

    @override protected void onsaveinstancestate(bundle outstate) { super.onsaveinstancestate(outstate); charsequence title = mdrawerlayout.isdraweropen(mleftdrawer) ? mdrawertitle:mtitle; outstate.putcharsequence(key_state_title, title); }

  • on oncreate() of activity:

    if (saveinstancestate!=null) { settitle(savedinstancestate.getcharsequence(key_state_title)); }

hope help.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -