<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    demibug

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      24 Posts :: 3 Stories :: 2 Comments :: 0 Trackbacks
    Android程序?qū)崿F(xiàn)動態(tài)OptionsMenu
    默認(rèn)使用的菜單例子都是創(chuàng)建的靜態(tài)菜單,在某些時候會不方便,比如: 
    一篇文章的顯示,按menu有加入收藏的功能,那實現(xiàn)的是如果未加入收藏,則是加入收藏的操作,否則是取消收藏的操作。 
    但onCreateOptionsMenu是實現(xiàn)不了這個功能的,它只會運行一次,如果再次按下menu,則不會變化。 

    我們看看程序說明: 
    public boolean onCreateOptionsMenu (Menu menu) 
    Initialize the contents of the Activity
    's standard options menu. You should place your menu items in to menu. 
    This is only called once, the first time the options menu is displayed. To update the menu every time it is displayed, see onPrepareOptionsMenu(Menu). 
    The 
    default implementation populates the menu with standard system menu items. These are placed in the CATEGORY_SYSTEM group so that they will be correctly ordered with application-defined menu items. Deriving classes should always call through to the base implementation. 
    You can safely hold on to menu (and any items created from it), making modifications to it as desired, until the next time onCreateOptionsMenu() is called. 
    When you add items to the menu, you can implement the Activity
    's onOptionsItemSelected(MenuItem) method to handle them there. 
    Parameters 
    menu The options menu in which you place your items. 
    Returns 
    You must 
    return true for the menu to be displayed; if you return false it will not be shown. 
    See Also 
    onPrepareOptionsMenu(Menu) 
    onOptionsItemSelected(MenuItem)

    也就是說明了它是第一次顯示菜單時調(diào)用的,每次更新,需要定義onPrepareOptionsMenu:
    public boolean onPrepareOptionsMenu (Menu menu) 
    Prepare the Screen
    's standard options menu to be displayed. This is called right before the menu is shown, every time it is shown. You can use this method to efficiently enable/disable items or otherwise dynamically modify the contents. 
    The default implementation updates the system menu items based on the activity's state. Deriving classes should always call through to the base class implementation.
    代碼例子:
    01.//code from www.aslibra.com
    02.public boolean onPrepareOptionsMenu(Menu menu) {
    03.menu.clear();
    04.if(isFavoutite){
    05.menu.add(0, NFav_ID, 0, R.string.menu_not_favourite).setIcon(R.drawable.ic_tab_selected_contacts);
    06.}else{
    07.menu.add(0, Fav_ID, 0, R.string.menu_favourite).setIcon(R.drawable.ic_tab_selected_contacts);
    08.}
    09.menu.add(0, Del_ID, 0, R.string.menu_delete).setIcon(R.drawable.ic_tab_selected_contacts);
    10.return super.onPrepareOptionsMenu(menu);
    11.}
    posted on 2011-11-08 21:25 Hiji 閱讀(213) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 久久99精品免费视频| 亚洲精品视频免费| 免费大片黄在线观看yw| 亚洲AV永久精品爱情岛论坛| 久久久免费观成人影院| 亚洲热妇无码AV在线播放| 久久av免费天堂小草播放| 亚洲人成网亚洲欧洲无码久久| 国产免费牲交视频免费播放| 亚洲精品中文字幕乱码三区| 日本在线免费观看| 亚洲精品中文字幕麻豆| 午夜福利不卡片在线播放免费| 亚洲国产日韩精品| 日韩激情无码免费毛片| 污污免费在线观看| 亚洲精品国产美女久久久| 99视频精品全部免费观看| 亚洲妓女综合网99| 日本免费观看网站| 一级有奶水毛片免费看| 亚洲精品在线免费看| 暖暖日本免费在线视频| 一个人看的免费视频www在线高清动漫| 国产亚洲情侣一区二区无码AV | 国产成人高清亚洲| 国产在线一区二区综合免费视频| 亚洲视频一区二区在线观看| 成人毛片免费在线观看| 一个人免费观看日本www视频 | 大学生美女毛片免费视频| 四虎精品免费永久免费视频| 国产A在亚洲线播放| 国产美女在线精品免费观看| 免费无码一区二区| 亚洲色av性色在线观无码| 午夜免费福利网站| 久别的草原电视剧免费观看| 亚洲熟妇无码AV| 亚洲精品高清国产一线久久| 免费鲁丝片一级观看|