forked from ruboto/ruboto
-
Notifications
You must be signed in to change notification settings - Fork 0
Tutorial: Add a menu
Uwe Kubosch edited this page Aug 29, 2013
·
10 revisions
Add a menu to a newly generated app.
You should have completed the Getting started with Ruboto tutorial. You can use an android device or the emulator to run your app.
This tutorial has been tested on the following configurations
| ruboto | jruby-jars | Device | api-level | Tester |
|---|---|---|---|---|
| 0.13.0 | 1.7.4 | Samsung Galaxy S3 | 16 | donV |
| 0.10.0 | 1.7.1 | Samsung Galaxy S3 | 15 | |
| 0.10.0 | 1.7.1 | Emulator | 15 | |
| 0.10.0 | 1.7.1 | Emulator | 10 | |
| 0.10.1 | – | Lenovo P700 | 15 | rystraum |
ruboto gen app --package org.ruboto.examples.menu_example
cd menu_example
rake install startYou should now see the familiar “What hath Matz wrought?”.

Add a callback for opening the menu. Edit the src/menu_example_activity.rb, and add the following method:
def onCreateOptionsMenu(menu)
menu.add('Action 1').set_on_menu_item_click_listener do |menu_item|
@text_view.text = menu_item.title
toast menu_item.title
true # Prevent other listeners from executing.
end
mi = menu.add('Action 2')
mi.set_icon $package.R::drawable::get_ruboto_core
mi.set_on_menu_item_click_listener do |menu_item|
@text_view.text = menu_item.title
toast menu_item.title
true # Prevent other listeners from executing.
end
true # Display the menu.
endrake install startAfter your app restarts, you should be able to press the menu button to diaply a menu. Selecting any of the menu items should pop up a toast with the title of the menu item.