Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use in java: setMenuItemClickListener? #101

Open
panovvitalik opened this issue Jun 8, 2020 · 2 comments
Open

How to use in java: setMenuItemClickListener? #101

panovvitalik opened this issue Jun 8, 2020 · 2 comments

Comments

@panovvitalik
Copy link

panovvitalik commented Jun 8, 2020

How I can implement menu item click on java? Which parameter type I should provide to setMenuItemClickListener method

ContextMenuDialogFragment contextMenuDialogFragment = ContextMenuDialogFragment.newInstance(menuParams);
contextMenuDialogFragment.setMenuItemClickListener(???);

He show me the tint:

Required type: Function2

What is it?

If I try to provide this with implemented: MenuItem.OnMenuItemClickListener interface, I get such error:

Required type:
Function2
Provided:
OnMenuItemClickListener
@anbuqi
Copy link

anbuqi commented Aug 18, 2020

We just need a lambda:
contextMenuDialogFragment.setMenuItemClickListener((v, position) -> {

        return null;
    });

@MS893
Copy link

MS893 commented Nov 17, 2020

I have added the lambda, and then ? what do I have to do to make it works ? Thanks

My actual java code is :

private void initMenuFragment() {

    MenuParams menuParams = new MenuParams();
    menuParams.setActionBarSize((int) getResources().getDimension(R.dimen.tool_bar_height));
    menuParams.setMenuObjects(getMenuObjects());
    menuParams.setClosableOutside(false);        // permet de fermer le menu en cliquant sur une zone sans bouton
    mMenuDialogFragment = ContextMenuDialogFragment.newInstance(menuParams);
    mMenuDialogFragment.setItemClickListener(this);

}

private List<MenuObject> getMenuObjects() {

    List<MenuObject> menuObjects = new ArrayList<>();

    MenuObject close = new MenuObject();
    close.setResource(R.drawable.ic_close);

    MenuObject cam = new MenuObject("LIVE  CAMERAS");
    cam.setMenuTextAppearanceStyle(R.style.Context_Menu);
    cam.setResource(R.drawable.ic_camera);

    menuObjects.add(close);
    menuObjects.add(cam);

    return menuObjects;

}

@Override
public void onMenuItemClick(View clickedView, int position) {
    if (position == 1) {
        //
    } else if (position == 2) {
        //
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants