Android-subtitle in the Operation column, android-subtitle

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.