'In Master Detail Flow project in Android Studio, how could I save the title of the ItemDetailActivity when rotate a mobile?

In Master Detailed template in Android Studio, how could I save the title of the ItemDetailActivity when rotate a mobile? Since the title of the activity is changed acording to the list item in the ItemListActivity by the ItemDatailFragment using this code

appBarLayout.setTitle(mItem.content);

but, when change the state of the emulator from portrait to landscape the title change to the origin title from XML.



Solution 1:[1]

Today I found the solution! Since the fragment already save its state, and the fragment creation done in onCreateView(), so I repeat the following bold code in

   if (mItem != null) {
        ((TextView) rootView.findViewById(R.id.item_detail)).setText(mItem.details);
        **Activity activity = this.getActivity();
        CollapsingToolbarLayout appBarLayout = (CollapsingToolbarLayout) activity.findViewById(R.id.toolbar_layout);
        if (appBarLayout != null) {
            appBarLayout.setTitle(mItem.treatment);
        }**
    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ashraf qandeel