Menu.add onOptionsItemSelected - how to call class

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Menu.add onOptionsItemSelected - how to call class

Postby Mark Worsnop » Mon Dec 13, 2010 3:12 am

I got the menu item to appear and go to the ItemSelected function when clicked. I need to have it open another class. All of the buttons I have used so far I have the view.context to pass, but do not know how to do it from the menu item. Can anyone else please? THANK YOU!

Syntax: [ Download ] [ Hide ]
Using javascript Syntax Highlighting
  1.             @Override
  2.             public boolean onCreateOptionsMenu(Menu menu) {
  3.                 super.onCreateOptionsMenu(menu);
  4.  
  5.                 menu.add( 0,    1, 0, "Setup" )
  6.                         .setShortcut('1', 's')
  7.                         .setIcon(android.R.drawable.ic_menu_add);
  8.  
  9.                
  10.                 return true;
  11.             }
  12.  
  13.             @Override
  14.             public boolean onOptionsItemSelected(MenuItem item) {
  15.                 switch (item.getItemId()) {
  16.                 case 1:
  17.                    
  18.                 Intent intent = new Intent(   ???.getContext(), Setup.class);  <--- this line I dont know what to enter
  19.                 startActivity(intent);
  20.                        
  21.                     return true;
  22.                 }
  23.                 return super.onOptionsItemSelected(item);
  24.             }
  25.  
  26.  
Parsed in 0.016 seconds, using GeSHi 1.0.8.4
Mark Worsnop
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Dec 01, 2010 12:34 am

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 6 guests