Android, ListView prevent OnItemClick event when OnCreateContextMenu is called

57 Views Asked by At

I'm facing with a problem with my ListView, I'm trying to create a context menu when I long click on an item but when the OnCreateContextMenuList event is called I also have the OnItemClickListener event (and this one triggers a dialog).

A snippet of my current code :

    ListView devicesList = (ListView)getView().findViewById(R.id.devices_list);

    devicesList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //Here I create my dialog (I voluntarily hidden the code because I think it doesn't matter (well I think))
    });

    devicesList.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
        @Override
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
            Log.d(TAG, "onCreateContextMenu: yes");
            //Here I need to prevent the OnItemClick event to create with serenity my menu
        }
    });
1

There are 1 best solutions below

0
On

Could be a problem with your layout. Maybe some view is overlapping your ListView.