Posted By

variable3 on 04/27/11


Tagged

contextMenu OptionMenu


Versions (?)

Android create OptionMenu, ContextMenu


 / Published in: Java
 

  1. Create OptionMenu-(Override onCreateOptionsMenu())--
  2.  
  3. public boolean onCreateOptionsMenu(Menu menu) {
  4. MenuInflater inflater = getMenuInflater();
  5. inflater.inflate(R.layout.menuex, menu);
  6. return true;
  7. }
  8.  
  9.  
  10. Create ContextMenu-(Override onCreateContextMenu())--
  11. ----------------------------------------------------
  12. Button btn = (Button) findViewById(R.id.btnContext);
  13. registerForContextMenu(btn);
  14.  
  15. public void onCreateContextMenu(ContextMenu menu, View v,
  16. ContextMenuInfo menuInfo) {
  17. super.onCreateContextMenu(menu, v, menuInfo);
  18. MenuInflater inflater = getMenuInflater();
  19. inflater.inflate(R.layout.menuex, menu);
  20.  
  21. menux an xml file--
  22. <menu xmlns:android="http://schemas.android.com/apk/res/android">
  23. <item android:id="@+id/new_game"
  24. android:title="Web" />
  25. <item android:id="@+id/help"
  26. android:title="Help" />
  27. <item android:id="@+id/app"
  28. android:title="Application" />
  29. </menu>

Report this snippet  

You need to login to post a comment.