Project

General

Profile

Evolution #3746

Add menu id in MenuWrappers

Added by Erwan L. almost 7 years ago. Updated 11 months ago.

Status:
Nouveau
Priority:
Normal
Assignee:
Category:
Core
Target version:
Start date:
02/05/2014
Due date:
% Done:

0%

Estimated time:
Bdc:

Description

In initializeMenu method, replace id 0 by real menuId.
In dispatch method, use the real id in switch.

Ex:


    @Override
    public void initializeMenu(Menu menu, FragmentActivity activity,
            Fragment fragment, Context ctx) {

        if ((activity != null && activity instanceof SyncMenuInterface)
                || (fragment != null && fragment instanceof SyncMenuInterface)) {

            this.item = menu.add(
                    AnticounterfeitMenu.SYNC,
                    AnticounterfeitMenu.SYNC,
                    Menu.NONE,
                    R.string.menu_item_sync);

            this.item.setShowAsAction(ActionMenuItem.SHOW_AS_ACTION_ALWAYS);
            this.item.setVisible(false);
            this.item.setIcon(R.drawable.action_sync);
        }
    }

    @Override
    public boolean dispatch(MenuItem item, Context ctx, Fragment fragment) {
        boolean result;

        SyncMenuInterface aboutMenu = null;

        if (fragment instanceof SyncMenuInterface) {
            aboutMenu = (SyncMenuInterface) fragment;
        } else if (ctx instanceof SyncMenuInterface) {
            aboutMenu = (SyncMenuInterface) ctx;
        }

        if (aboutMenu != null) {
            switch (item.getItemId()) {
                case AnticounterfeitMenu.SYNC:
                    aboutMenu.onClickSync(this);
                    result = true;
                    break;
                default:
                    result = false;
                    break;
            }
        } else {
            result = false;
        }
        return result;
    }


Recurrences

History

#1Updated by Gregg C. almost 7 years ago

In case of two menu items in the same menu wrapper (like CrudEditDelete), what id should i put in menuId ?
Currently, it all works very well if you use the dispatch method. If you want to use the classic android mechanics to manage the menu item click, you may also use it to create the menuItem.
You can do it when you create your own menu wrapper, but the one already generated works well.

Also available in: Atom PDF

Go to top
Add picture from clipboard (Maximum size: 200 MB)