Android make a context menu from a menu option
-
10-02-2021 - |
Question
So basically all I want is a go from a menu to a context menu that has a list of items, so if you click on an option menu it will open up a context menu with a list of options.
All the examples I found seemed to only be for listview or webview.
Is there some other "proper" way to make a list of items from menu options?
Solution
So if I'm understanding your right, you want to launch a Context Menu from an Options Menu. You should not do this. From the android documentation:
A context menu is conceptually similar to the menu displayed when the user performs a "right-click" on a PC. You should use a context menu to provide the user access to actions that pertain to a specific item in the user interface. On Android, a context menu is displayed when the user performs a "long press" (press and hold) on an item.
You'd never do a "long press" on an Options Menu item. People just aren't used to doing that.
Try launching another activity instead or using a dialog.
OTHER TIPS
If you have a fixed list of options in mind you might be looking for submenus, which are explained here: http://developer.android.com/guide/topics/ui/menus.html
If you are looking to dynamically build a list of options with an adapter you might find AlertDialog.Builder useful along with its setAdapter
method.