Open main menu

CDOT Wiki β

Changes

MAP524/DPS924 Lecture 5

47 bytes added, 07:47, 20 July 2015
ListView
== ListView ==
This should be as simple as is very similar to a spinner, it appears to do does essentially the same thing, but it's a bit more complicated to build. Follow these steps:
* Create a new Android app and name it My List.
* 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.