开发者

Android listview Items and menu

开发者 https://www.devze.com 2023-04-02 14:43 出处:网络
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 th

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消