Open main menu

CDOT Wiki β

Changes

MAP524/DPS924 Lecture 5

54 bytes added, 17:05, 18 July 2015
Context Menu
* First let's register the list view for a Context Menu by adding this line to our activity :
<presource lang="java">registerForContextMenu(lv);</presource>
* Now add this method to create our context menu:
<presource lang="java">@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, v.getId(), 0, "Make a Phone Call");
menu.add(0, v.getId(), 0, "Send an SMS Message");
}</presource>
* Now add the listener method like this:
<presource lang="java">@Override
public boolean onContextItemSelected(MenuItem item) {
if (item.getTitle() == "Make a Phone Call") {
}
return true;
}</presource>
* You can now run your app and test the context menu.