Menu Integration

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Menu Integration

Postby baskar » Thu Apr 10, 2008 1:57 pm

Hi All,

How to Menu Integration in android...

suppose my application interact with Nodepad through Menu..

please help me...


Regards,
Baskar
baskar
Developer
Developer
 
Posts: 46
Joined: Wed Dec 26, 2007 6:03 am
Location: India

Top

Postby plusminus » Fri May 23, 2008 9:59 am

Hello baskar,

menus (via the menu-button) are very easy in Android, you need to override 2-3 methods: [font=Courier New]onCreateOptionsMenu[/font], [font=Courier New]onPrepareOptionsMenu[/font] and [font=Courier New]onMenuItemSelected[/font], like this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         @Override
  2.  
  3.         public boolean onCreateOptionsMenu(Menu menu) {
  4.  
  5.                 menu.add(0, MENU_TRAFFIC_ID, getString(R.string.maps_menu_traffic), R.drawable.traffic_on_48);
  6.  
  7.                 menu.add(0, MENU_QUIT_ID, getString(R.string.maps_menu_quit), R.drawable.exit_48);             
  8.  
  9.                 return true;
  10.  
  11.         }
  12.  
  13.  
  14.  
  15.         @Override public boolean onPrepareOptionsMenu(final Menu menu) {
  16.  
  17.                 if(super.mMapView.isTraffic())
  18.  
  19.                         menu.findItem(MENU_TRAFFIC_ID).setIcon(R.drawable.traffic_off_48);
  20.  
  21.                 else
  22.  
  23.                         menu.findItem(MENU_TRAFFIC_ID).setIcon(R.drawable.traffic_on_48);
  24.  
  25.  
  26.  
  27.                 return super.onPrepareOptionsMenu(menu);
  28.  
  29.         }
  30.  
  31.  
  32.  
  33.         @Override
  34.  
  35.         public boolean onMenuItemSelected(final int featureId, final Item item) {
  36.  
  37.                 switch(item.getId()){
  38.  
  39.                         case MENU_TRAFFIC_ID:
  40.  
  41.                                 super.mMapView.toggleTraffic();
  42.  
  43.                                 return true;
  44.  
  45.                         case MENU_QUIT_ID:
  46.  
  47.                                 this.setResult(Constants.SUBACTIVITY_RESULTCODE_CHAINCLOSE_QUITTED);
  48.  
  49.                                 this.finish();
  50.  
  51.                                 return true;
  52.  
  53.                 }
  54.  
  55.  
  56.  
  57.                 return super.onMenuItemSelected(featureId, item);
  58.  
  59.         }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests