Android: How to find the position clicked from the context menu

Posted by Josemalive on Stack Overflow See other posts from Stack Overflow or by Josemalive
Published on 2010-03-16T10:41:26Z Indexed on 2010/03/16 10:46 UTC
Read the original article Hit count: 290

Hi,

I have a list view filled with data. I set up a context menu for the listview using the following code:

list.setOnCreateContextMenuListener
(
  new View.OnCreateContextMenuListener() 
  {
        public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) 
        {
       AdapterContextMenuInfo mi =(AdapterContextMenuInfo) menuInfo;
       menu.add(0, 0, 0, "Delete item");                
    }
   }
);

I have the following method override to control de contextmenu menuitem selected:

@Override
public boolean onContextItemSelected(MenuItem item) 
{
  switch(item.getItemId()) 
  { 
  case 0: 
    ShowAlert("hello from delete item");
    break; 
  default: 
  return super.onContextItemSelected(item); 
  } 
  return true; 
}

In this overrided method, how could i find the item of the list view that was clicked?

Thanks in advance. Best Regards. Jose

© Stack Overflow or respective owner

Related posts about android

Related posts about android-sdk