Background
I have an app which has sub menus in the action bar, for selecting the sorting type.
It works really well if you just tap the action items.
Here's how a submenu looks like on the actionBar:
The code
To make it easy to understand what I did, here's a short, simple version of just the sub menu part:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.test.MainActivity" >
<item
android:icon="@drawable/ic_action_collections_sort_by_size_holo_dark"
android:title="sorting"
app:showAsAction="ifRoom">
<menu >
<group
android:checkableBehavior="single"
android:menuCategory="container" >
<item
android:id="@+id/menuItem_sortByInstallTime"
android:title="by install time">
</item>
<item
android:id="@+id/menuItem_sortByUpdateTime"
android:title="by update time">
</item>
<item
android:id="@+id/menuItem_sortByAppName"
android:title="by app name">
</item>
<item
android:id="@+id/menuItem_sortByPackageName"
android:title="by package name">
</item>
</group>
</menu>
</item>
</menu>
The problem
Starting with Kitkat (Android 4.4) , instead of clicking the items, users can hold the touch and leave it when they reach the item they want to choose.
The feature is shown here , under "Drag-to-Select". Most people don't know about this feature, but people have already reported a very annoying bug about it.
In case you try out the code above (or my app), and use this feature, you will notice that you won't be able to click the same action item again, unless you click on others first.
That's right, it's blocked till you choose something else.
I've tested this issue on a Nexus 4 with Kitkat, and can confirm it.
Looking at other apps (even Google's apps), I can notice a similar issue: even though I can't find an exact example of having a grouped sub-menu, for regular sub menus, the action item is blocked for a single time. Clicking on it again will release it.
The question
Why does this occur?
Is there anything wrong with my code?
Is this a bug?
How can I fix it?
If there is no fix, should I just create my own popup menu, or is there another workaround?
I can recreate it too. I checked the AOSP's issue tracker and didn't find anything, but it certinaly appears to be a bug.
I think it's related to the
ListPopupWindow.ForwardingListener
, but I'm not certain exactly where the problem occurs right now.Call
Activity.invalidateOptionsMenu
after you select aMenuItem
.Limitations
Unfortunately, it looks like this solution is only viable for menu items not placed in the action bar's overflow menu. If you'd like to follow further updates regarding this problem, you should refer to issue #69205 on the AOSP's issue tracker.