Rajkiran
Rajkiran

Reputation: 16193

Do not show context menu for first listItem in the ListView

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?

Upvotes: 0

Views: 566

Answers (1)

waqaslam
waqaslam

Reputation: 68177

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;
    }
});

Upvotes: 2

Related Questions