Dennie
Dennie

Reputation: 2651

Check value to disable/enable Context Menu Item (android)

In my application has a ListView. When long press on item the "Context Menu" will appear. I want to check the data ID, then set disable/enable to my Context Menu "Items". I can not find out the function like getMenuInfo() or something like this.

@Override
public void onCreateContextMenu(ContextMenu menu , View v, ContextMenuInfo menuInfo)
{       
    super.onCreateContextMenu(menu, v, menuInfo);       
    menu.add(0, ADD_FAVORITE_ID, 0, "Check");       
    menu.add(0, ADD_FAVORITE_ID, 0, "UnCheck").setEnabled(false);                       
}

Upvotes: 3

Views: 4910

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006664

AdapterView.AdapterContextMenuInfo info=(AdapterView.AdapterContextMenuInfo)menuInfo();

Then, info.id is the _ID of whatever item was long-tapped in your ListView.

Upvotes: 4

Related Questions