Archive

Posts Tagged ‘Android’

[Android]Menu events

February 6, 2011 Leave a comment

onCreateOptionsMenu

  • Trigged the first time an Activity’s menu is displaed
    • Can Define a menu for an Activity
    • Menu.add() method
    • Menu.addSubMenu() method
  • Can use Menu resource in Xml file
    • MenuInflator.inflate() method

onOptionsItemSelected

  • MenuItem.getItemId() method and R.id.xxx
  • When the menu item selected

onPrepareOptionsMenu

  • Can modify a Menu based on an application’s current state

onCreateContextMenu

  • Can define a Context Menu
  • registerForContextMenu(view)  : Can register Activity-specific Context Menu for an Activity
  • Can use Menu resource in Xml file
    • MenuInflator.inflate() method

onContextItemSelected

  • When the context menu item selected

 

coding sample

sample

Categories: Android Tags: , ,