<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有加入收藏的功能,那實(shí)現(xiàn)的是如果未加入收藏,則是加入收藏的操作,否則是取消收藏的操作。 
    但onCreateOptionsMenu是實(shí)現(xiàn)不了這個功能的,它只會運(yù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 閱讀(210) 評論(0)  編輯  收藏

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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 国产午夜亚洲精品国产成人小说| 在线看片免费人成视频福利| 中文日韩亚洲欧美制服| 久久亚洲AV成人无码| 亚洲AV日韩AV鸥美在线观看| 亚洲狠狠婷婷综合久久久久 | 亚洲av无码成人精品国产| 亚洲一区二区三区在线观看蜜桃| 亚洲美女精品视频| 亚洲成人福利网站| 亚洲成a人不卡在线观看| 亚洲国产精品人久久电影| 亚洲伊人久久大香线蕉在观| 亚洲AV无码国产精品色| 亚洲午夜一区二区三区| 国产亚洲精品影视在线| 亚洲色大成网站WWW国产| 337p日本欧洲亚洲大胆人人| 美国免费高清一级毛片| 一级特黄色毛片免费看| 免费观看成人久久网免费观看| 久久aa毛片免费播放嗯啊| 亚洲成年人免费网站| 无码专区永久免费AV网站 | 麻豆安全免费网址入口| 一级做a爰片久久毛片免费陪 | 亚洲国产精品久久丫| 亚洲精品亚洲人成在线播放| 亚洲精品永久在线观看| 激情吃奶吻胸免费视频xxxx| 久久久久久噜噜精品免费直播| 大地资源网高清在线观看免费| 99久久精品免费视频| 男男AV纯肉无码免费播放无码| 老司机永久免费网站在线观看| 日产国产精品亚洲系列| 亚洲成AV人片天堂网无码| 亚洲激情校园春色| 老子影院午夜伦不卡亚洲| 三年片在线观看免费西瓜视频| 桃子视频在线观看高清免费完整|