How to handle dragging and dropping submenu items in Kitkat?

Background

I have an application that has a submenu in the action bar to select the sort type.

It works really well if you just click on the action elements.

This is what the actionBar submenu looks like:

enter image description here

Code

To make it easier to understand what I did, here's a short, simple version of just part of the submenu:

<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>

      

Problem

Starting with Kitkat (Android 4.4), instead of clicking on items, users can hold and leave when they reach the item they want to select.

The function is shown here under the " Drag and Drop to " section . Most people are not aware of this function, but people have already reported a very annoying bug about it.

In case you try the code above (or my application) and use this function, you will notice that you cannot click the same action item again unless you click on others first.

That's right, this is locked until you choose something else.

I've tested this issue on a Nexus 4 with Kitkat and can confirm it.

If I look at other apps (even Google apps), I can see a similar problem: although I can't find an exact example of having a grouped submenu, for regular submenus the action item is blocked for once. Pressing it again will release it.

Question

Why is this happening?

Is there something wrong with my code?

This is mistake?

How can I fix this?

If there is no fix, should I just create my own popup menu, or is there another workaround?

+2


source to share


1 answer


This is mistake?

I can recreate it too. I checked the AOSP questionnaire and found nothing, but this certinaly seems to be a bug.

Why is this happening?

I think it has something to do with ListPopupWindow.ForwardingListener

, but I don't know exactly where this issue is occurring now.

How can I fix this?



Call Activity.invalidateOptionsMenu

after selection MenuItem

.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menuItem_sortByInstallTime:
            // Do something
            break;
        case R.id.menuItem_sortByUpdateTime:
            // Do something
            break;
        case R.id.menuItem_sortByAppName:
            // Do something
            break;
        case R.id.menuItem_sortByPackageName:
            // Do something
            break;
        default:
            break;
    }
    invalidateOptionsMenu();
    return true;
}

      

Limitations

Unfortunately, it looks like this solution is only available for menu items not placed in the action bar overflow menu. If you would like to keep track of further updates to this issue, please refer to issue # 69205 in the AOSP tracker.

+2


source







All Articles