0

I have a listview which has some listItems in it. I have registered the listview for context menu using registerForContextMenu(mListView);. Now what I want is that, if the user long presses on the first item of the listview, the context menu for that item should not be shown, but for all the rest items, it should popup the context menus if the user long presses on them. Can we do this?

Rajkiran
  • 15,845
  • 24
  • 74
  • 114
  • See this answer: http://stackoverflow.com/a/2453661/1037294 – a.ch. Apr 27 '12 at 09:13
  • I could not found a way to prevent the context menu from getting generated in that thread. What it is giving is the position of the the contextMenuItem that is being selected, but its not preventing the dialog from being shown – Rajkiran Apr 27 '12 at 10:09

1 Answers1

2

Instead, i would suggest you to use OnItemLongClickListener which will return position value of long-pressed item. By considering that value, you may decide either to show dialog with list of options or just ignore it.

For example:

yourListView.setOnItemLongClickListener(new OnItemLongClickListener() {
    @Override
    public boolean onItemLongClick(AdapterView<?> parent, View view,
            int position, long id) {
        if(position != 0){  //ignoring first item from list
            //do whatever you want
        }
        return false;
    }
});
waqaslam
  • 67,549
  • 16
  • 165
  • 178