How to open a context menu on click of menu button on android device? Can anyone help me please..
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Select");
menu.add(0, v.getId(), 0, "Gmail");
menu.add(0, v.getId(), 0, "Facebook");
menu.add(0, v.getId(), 0, "Twitter");
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if(item.getTitle()=="Gmail"){function1(item.getItemId());}
else if(item.getTitle()=="Facebook"){function2(item.getItemId());}
else if(item.getTitle()=="Twitter"){function3(item.getItemId());}
return true;
}
How open the above context menu on click of menu button ?
Because, Context Menu is for a specific view,
A contextual menu offers actions that affect a specific item or context frame in the UI. You can provide a context menu for any view, but they are most often used for items in a ListView, GridView, or other view collections in which the user can perform direct actions on each item.
To show a context menu on long click, most clients will want to call
registerForContextMenu(View)and overrideonCreateContextMenu(ContextMenu, View, ContextMenu.ContextMenuInfo).For menu Button of device you can use an Options Menu
Update:
I never try this, but you can do something like,
Handle Menu button press event of device,
Put line inside it,