0

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

Bharat
  • 1,044
  • 15
  • 34

1 Answers1

0

I feel the following link should able to solve your problem

how to implement a long click listener on a listview

and one more thing , are you calling your #delete() method to register listview long press listener ?

Community
  • 1
  • 1
Anil Raavi
  • 131
  • 1
  • 10
  • Yes I'm calling the delete method to implement listview onItemLongClickListener – Bharat Mar 20 '17 at 07:21
  • And , did you try above link ? – Anil Raavi Mar 20 '17 at 07:34
  • bro the link you gave is for direct longclick...But I want to implement longclick from popup menu...Thanks anyway – Bharat Mar 20 '17 at 09:11
  • Can you share code if possible? , i will try to solve that – Anil Raavi Mar 20 '17 at 09:15
  • I have already shared the code dude.The question itself is the code.See it i implemented onCreateContextMenu and onContextItemSelected...These are for popup menu.If delete was pressed the delete() method has to be triggered.But its not getting triggered – Bharat Mar 20 '17 at 12:29
  • Cool,I mean if you are working on some sample project . i can try it on my machine .Anyways if you can share sample project will work on it. – Anil Raavi Mar 20 '17 at 12:58
  • No dude its not possible...sorry for that – Bharat Mar 20 '17 at 13:28