views:

993

answers:

1

Hi, 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);                 
}
+2  A: 
AdapterView.AdapterContextMenuInfo info=(AdapterView.AdapterContextMenuInfo)menuInfo();

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

CommonsWare
Thanks for your code, It work! and the correct syntax is "menuInfo" ---> AdapterView.AdapterContextMenuInfo info=(AdapterView.AdapterContextMenuInfo)menuInfo;
Dennie