Android listview Items and menu
In my android application I have a listview that displaying user contacts. I need to implement a option menu that has a menu item Name "Add to favourites" which will add the selected contact from the listview to favourites list.
I am strugling of how to track the selected item from the listview to add to favourite list. Also The "Add to favourites" menu item should only display only when we press the menu button and if an Item in the listview have selected. Because there exists other buttons and all in the page and only it should display to add a cont开发者_StackOverflow中文版act to favourites list.
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info;
try {
info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
}
catch (ClassCastException e) { }
// get the item for which the menu is shown
Object item = getListAdapter().getItem(info.position);
}
精彩评论