Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);                       
}
like image 535
Dennie Avatar asked Jun 05 '26 21:06

Dennie


1 Answers

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

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

like image 162
CommonsWare Avatar answered Jun 10 '26 07:06

CommonsWare