how to get system default Options menus?

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

how to get system default Options menus?

Postby newbin » Sun Jul 26, 2009 7:25 am

dear all:
how to get system default Options menus?like settings,add and so on.please help.
newbin
Freshman
Freshman
 
Posts: 2
Joined: Sat Jul 11, 2009 5:01 am

Top

Postby Erykgecko » Mon Jul 27, 2009 11:07 pm

This drove me mad for a while trying to find it too, but its actually pretty simple

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     @Override
  2.  
  3.     public boolean onCreateOptionsMenu(Menu menu)
  4.  
  5.     {
  6.  
  7.       super.onCreateOptionsMenu(menu);  
  8.  
  9.       MenuItem item = menu.add(0,1,0,"option 1");
  10.  
  11.       item = menu.add(0,2,0,"option 2");
  12.  
  13.       item = menu.add(0,3,0,"option 3");
  14.  
  15.       item = menu.add(0,4,0,"option 4");
  16.  
  17.                 return true;
  18.  
  19.  }  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


That should give you a basic 4 button menu when you press the menu key. Obviously if you want more buttons add more lines.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     public boolean onOptionsItemSelected(MenuItem item)
  2.  
  3.        {
  4.  
  5.  
  6.  
  7.            if(item.getItemId()==1){
  8.  
  9.                      //do stuff!
  10.  
  11.                     }
  12.  
  13.            if(item.getItemId()==2){
  14.  
  15.                      //do more stuff!
  16.  
  17.                     }
  18.  
  19.            if(item.getItemId()==3){
  20.  
  21.                      //do different stuff!
  22.  
  23.                     }
  24.  
  25.            if(item.getItemId()==4){
  26.  
  27.                      //do more different stuff!
  28.  
  29.                     }}
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


pretty simple :) Hope this helps
Erykgecko
Junior Developer
Junior Developer
 
Posts: 20
Joined: Sat May 16, 2009 5:32 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests