ListView . onitemlongclicklistener

  • Replies:2
Bruno Apfelsini
  • Forum posts: 10

Jun 27, 2013, 8:28:23 PM via Website

Hi B)

I read the last couple of days many texts and tuts on the Internet but I didn't find
the right answer.

I have a listview which shows data from a database - it's working.
I set up a ContextMenu for the listview and ... it's working too.

But in order to e.g. edit the clicked item - I need the id/position of
the clicked item when I click a Long click - and the ContextMenue appears

How can I achive this - thanks in advance

— modified on Jun 27, 2013, 8:31:28 PM

Reply
James Liu
  • Forum posts: 15

Jun 30, 2013, 5:19:04 PM via Website

First, you need to enable the listView for long click:

1list.setLongClickable(true);

Then, you need to set long click listener on the item of the ListView:

1list.setOnItemLongClickListener(new OnItemLongClickListener() {
2 @Override
3 public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
4 final int arg2, long arg3) {
5
6}
7});

Reply
Bruno Apfelsini
  • Forum posts: 10

Jun 30, 2013, 7:12:06 PM via Website

Thanks :)

Reply