Note that there are some explanatory texts on larger screens.

plurals
  1. POFix Navigation Drawer Title change on orientation change?
    text
    copied!<p>When the orientation is changed on my app, the title in the action bar changes from the title of the fragment selected in the nav drawer to the title of the app.</p> <p>The <a href="http://developer.android.com/training/implementing-navigation/nav-drawer.html" rel="nofollow">Navigation drawer example app</a> retains it's title on orientation change because it's fragment is a subclass of the main activity, and has this line of code</p> <pre><code>getActivity().setTitle(planet); </code></pre> <p>Now i'm bit a newbie so i wouldn't know how to retain the title, and implement the code, can you guys help?</p> <p>Just in case any of you wanna see, here is the subclass for the PlanetFragment</p> <pre><code>public static class PlanetFragment extends Fragment { public static final String ARG_PLANET_NUMBER = "planet_number"; public PlanetFragment() { // Empty constructor required for fragment subclasses } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_planet, container, false); int i = 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; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload