I had a listview to which I've kept a popup menu.So I could get popup menu on long clicking an item of listview.My popup menu methods are as follows:
void delete()
{
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(ViewDetails.this, i+"", Toast.LENGTH_SHORT).show();
return true;
}
});
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo)
{
super.onCreateContextMenu(menu,v,menuInfo);
menu.setHeaderTitle("Click to delete");
menu.add(0,v.getId(),0,"Delete");
}
@Override
public boolean onContextItemSelected(MenuItem item)
{
if(item.getTitle()=="Delete")
{
delete();
}
return true;
}
My problem is that I'm unable to execute the code in onItemLongClick method. Actually what I want to do is deleting the List item on pressing the delete option that comes from the popup menu...Someone please help me...Thanks in advance