我曾经这样做:
menu.setHeaderTitle("Available Actions");
android.view.MenuItem Edit = menu.findItem(R.id.edit);
android.view.MenuItem Delete = menu.findItem(R.id.delete);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
int position = info.position;
ListView lv = (ListView) v;
int firstVisible = lv.getFirstVisiblePosition();
View rowView = lv.getChildAt(position - firstVisible);
if (Rateit.isUserLoggedIn == true) {
{
Edit.setVisible(true);
Delete.setVisible(true);
} else {
Edit.setVisible(false);
Delete.setVisible(false);
}
} else {
Edit.setVisible(false);
Delete.setVisible(false);
}
现在菜单是通过不膨胀布局设置的,但是:
menu.add(2, 1, 0, "Edit");
menu.add(2, 2, 0, "Delete");
但是,我找不到需要将itemId
(方法中的第二个参数)分配给/的add
方法,所以我可以将它们设置为可见或不可见?有人知道怎么做吗?Edit
Delete