I can show a context menu this is great.
Now I don't want the user to be able to close the context menu without choosing an option how would I go about doing this?
Or should I stop being lazy and move to a dialog?
There is no public API to control back-key behavior on context menu.
As you suggested your best option is to move to dialogs.
Related
I want is a go from a menu that has a list of objects, if you select an option menu another list should appear.
The examples I found seemed to be for listview or webview.
There another way to make a selection from menu options?
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.
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.
I have a menu that I want to appear on the screen when the app starts, without the user having to press the menu key.
What is a good way to achieve that?
Maybe Activity.openOptionsMenu() or Activity.openContextMenu?
Is there any way to do a popup menu that is activated by a process within the program, such as the JPopupMenu class of Swing? All I can find in the android literature is an options menu that can only be activated by pressing a menu button, and the context menu that can only be activated by a long press.
You can use a TranslateAnimation
Maybe this is also helpful: http://developerlife.com/tutorials/?p=343
I would like to create a context menu (long press on a textview) that will show a list of options.
Difference from regular context menu will be, that the use is different: user will long click on the textview, menu will popup, user will not release finger, point to the menu item, release finger. This will fire the action.
Any idea how ot do it?>Can you refer me to an example
I don't know how to fully achieve it. But this might help you. You can create a context menu as shown here.
Hope this helps.
Unless you have a very specific use case, I'd recommend against changing how the user expects a context menu to behave, and stay with the default behaviour. It can lead to quite a jarring user experience.
How to open the ContextMenu in Android by Clicking a Button?
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.
Alternatively, if you need a button, you can implement the menu for the view and change the content dynamically.
Your question is bad and you should feel bad, given how readily available (if cryptic) the method behind this process is. This small tutorial helped me greatly.
http://www.mikeplate.com/2010/01/21/show-a-context-menu-for-long-clicks-in-an-android-listview/