RLScott
Newbie
I have a problem with my context menus. The items sensitive to long-press are items in a ListView of file names. The context menu has 3 items:
Delete this file
Rename this file
Display file info
It works fine except when I long-press an item near the top of the screen. Since the context menu likes to position itself by default just above the item that was long-pressed, the context menu is vertically compressed for items near the top of the screen, and all three menu choices are not visible at once. They can be scrolled to get to all three, but I don't want the user to have to scroll the menu. I would like to override the default positioning of the context menu. I realize that by doing so I will be breaking the visual association between the item the user long-pressed and the actions to be performed by the menu selections. But I can compensate for that by including the name of the item long-pressed in the context menu header, so the user will still know what item he long-pressed. So I just need to know how to override the default positioning of a context menu. My context menu is created entirely by code (no xml) as follows:
Delete this file
Rename this file
Display file info
It works fine except when I long-press an item near the top of the screen. Since the context menu likes to position itself by default just above the item that was long-pressed, the context menu is vertically compressed for items near the top of the screen, and all three menu choices are not visible at once. They can be scrolled to get to all three, but I don't want the user to have to scroll the menu. I would like to override the default positioning of the context menu. I realize that by doing so I will be breaking the visual association between the item the user long-pressed and the actions to be performed by the menu selections. But I can compensate for that by including the name of the item long-pressed in the context menu header, so the user will still know what item he long-pressed. So I just need to know how to override the default positioning of a context menu. My context menu is created entirely by code (no xml) as follows:
Code:
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
if (v == list) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;
{
File f = new File(path.get(info.position));
menu.setHeaderTitle(FileExplorer.zapExtension(f.getName()));
menu.add(Menu.NONE,0,0,"Delete this file");
menu.add(Menu.NONE,1,1,"Rename this file");
menu.add(Menu.NONE,2,2,"Display file info");
}
}
}