Skip to content

Instantly share code, notes, and snippets.

@thinkAmi
Created August 1, 2013 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkAmi/6135744 to your computer and use it in GitHub Desktop.
Save thinkAmi/6135744 to your computer and use it in GitHub Desktop.
RubotoでActionBar上にPopupMenuを作った時のサンプルコード
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_bar"
android:title="action"
android:showAsAction="ifRoom|withText"
/>
</menu>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/Popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Popup Sample"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/toast"
android:title="toast"
/>
<item
android:id="@+id/intent"
android:title="intent"
/>
</menu>
require 'ruboto/widget'
require 'ruboto/activity'
require 'ruboto/util/toast'
# intent start用
java_import "android.content.Intent"
java_import "android.net.Uri"
# popup用
java_import 'android.widget.PopupMenu'
# Log用
java_import 'android.util.Log'
class PopupmenuActivity
def on_create(bundle)
super
Log.v('POPUPMENU', 'on_create called')
self.setContentView(Ruboto::R::layout::main)
end
def on_create_options_menu(menu)
Log.v('POPUPMENU', 'on_create_options_menu called')
self.getMenuInflater().inflate(Ruboto::R::layout::action_bar_menu, menu)
true
end
def on_options_item_selected(item)
Log.v('POPUPMENU', 'onOptionsItemSelected called')
view = findViewById(item.getItemId())
popup = PopupMenu.new(self, view)
popup.getMenuInflater().inflate(Ruboto::R::layout::popup_menu, popup.getMenu())
popup.setOnMenuItemClickListener(MenuItemClickListener.new(self))
popup.show()
true
end
def tap_popup_menu(itemId)
case itemId
when Ruboto::R::id::toast
toast 'select toast'
when Ruboto::R::id::intent
intent = Intent.new(Intent::ACTION_VIEW)
intent.setData(Uri.parse("http://ruboto.org/"))
startActivity(intent)
else
toast 'Popup Selected' + itemId.to_s
end
end
end
class MenuItemClickListener
def initialize(activity)
@activity = activity
end
def onMenuItemClick(item)
@activity.tap_popup_menu(item.getItemId())
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment