here is a list of contact in ListView
, i want when user longClick
on any contacts then ContextMenu
popup should be show \"call\"and \"sen
Try to swap the lines from:
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Select The Action");
menu.add(0, v.getId(), 0, "Call");
menu.add(0, v.getId(), 0, "Send SMS");
}
To:
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenu.ContextMenuInfo menuInfo) {
menu.setHeaderTitle("Select The Action");
menu.add(0, v.getId(), 0, "Call");
menu.add(0, v.getId(), 0, "Send SMS");
super.onCreateContextMenu(menu, v, menuInfo);
}
Update
Remove listView.setOnItemLongClickListener
because you can't use a longclicklistener and a context menu at the same time. To show a context menu you just need to call registerForContextMenu(listView)
after you inflated your view and override onCreateContextMenu()
for menu creation and onContextItemSelected()
to handle the user action.
Remove longpress method from your code just, hope it will working