When I noticed that most navigations options of the Actionbar are getting deprecating I started quickly to replace the Actionbar with the new Android Toolbar. Mostly working well I've still run into problems. I have a spinner in my toolbar which contents disappear at rotation.
My Toolbar is located in the layout of the MainActivity like this:
<android.support.v7.widget.Toolbar
android:id="@+id/act_main_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</android.support.v7.widget.Toolbar>
In onCreate in the MainActivity I'm inflating menu buttons, logo and spinner
mToolbar.setLogo(R.drawable.action_bar_icon);
Toolbar.inflate(this, R.layout.toolbar_spinner, mToolbar);
mToolbar.inflateMenu(R.menu.toolbar_menu);
At screen rotation the Spinner's contents disappear, the spinner is still there just empty. The SpinnerAdapter containing the elements still contains them, it just as the adapter has been deattached from the toolbar.
Edit updated code for the SpinnerAdapter creation:
The adapter is set in onCreate of the fragment:
mToolbar = (Toolbar) getActivity().findViewById(R.id.act_main_toolbar);
mToolbarSpinner = (Spinner) mToolbar.findViewById(R.id.act_main_toolbar_spinner);
mToolbarSpinner.setAdapter(adapter);
Then I have asyncTasks which retrieve the data, once the retrieval is done I use the following call to present the data:
adapter.notifyDataSetChanged()
Edit 2
The issue occurred because the reference to the mToolbar created in onCreate was becoming faulty after Screen rotation. By moving the following to onCreateView it started to work:
mToolbar = (Toolbar) getActivity().findViewById(R.id.act_main_toolbar); //This fixed it!
mToolbarSpinner = (Spinner) mToolbar.findViewById(R.id.act_main_toolbar_spinner);
mToolbarSpinner.setAdapter(adapter);