0

I'm using a Contextual Action Bar (CAB) in my app and setting the visibility of some menu items depending on which item is selected in my ListView. I've noticed that the CAB doesn't actually reflect the visibility of the menu items until I tap the menu button at the right end of the CAB.

Here is the code for my onPrepareActionMode method:

public boolean onPrepareActionMode(ActionMode actionMode, Menu menu)
{
    if (lstSortColumns.getCheckedItemPosition() == 0)
    {
        menu.findItem(R.id.action_move_up).setVisible(false);
    }
    else
    {
        menu.findItem(R.id.action_move_up).setVisible(true);
    }
    if (lstSortColumns.getCheckedItemPosition() == (lstSortColumns.getCount() - 1))
    {
        menu.findItem(R.id.action_move_down).setVisible(false);
    }
    else
    {
        menu.findItem(R.id.action_move_down).setVisible(true);
    }
    return true;
}

Am I missing something, or is this a bug in Android?

EDIT:

I was able to get around this by setting android:showAsAction="never" for the menu items in the menu xml file.

2
  • are you updating the CAB? Aug 22, 2014 at 3:01
  • I'm not sure what you mean by updating the CAB. I call actionMode.invalidate() when I need the visibility of the menu items updated.
    – Dave F
    Aug 22, 2014 at 3:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.