Android-subtitle in the Operation column, android-subtitle
Our goal is to add an option menu to the right of the Operation column. Click it to display or hide the subtitle in the Operation column.
Since the operation bar appears after API11, you must consider compatibility issues. The option menu is invisible to devices earlier than API11. Create res/menu-v11, put the xml of menu into it,
Add this option menu Item.
Step 1: setHasOptionsMenu (true)
2. onCreateOptionsMenu ()
3. onOptionsItemSelected ()
It seems that the problem has been solved perfectly. In fact, there is a serious bug. This is the problem of rotating a classic device. If the subtitle is displayed, the subtitle is blank after rotation, and the title of the option menu changes to show_subtitle.
How can this problem be solved? Some may want to save the fragment instance so that it is retained during the device rotation. This idea is great, but it ignores that the problem of displaying the subtitle or option menu is a view problem, regardless of whether the fragment instance is saved,Fragment view will be destroyedThe reason is the possibility of resource reconfiguration.
No matter whether there is a subtitle or not, there will be no view reconstruction. Therefore, we need to add a flag in fragment to store whether the subtitle is displayed. When the view is re-built, the flag is used to determine whether to display the subtitle.
Finally, if the data displayed on the view layer is set in the non-create view method, after the device rotates the configuration change behavior, the view is destroyed and rebuilt, even if the fragment instance is retained.