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

is this code works in java? #52

Open
AymenBoukhari opened this issue Feb 22, 2024 · 3 comments
Open

is this code works in java? #52

AymenBoukhari opened this issue Feb 22, 2024 · 3 comments

Comments

@AymenBoukhari
Copy link

Hi, i just want to use this menu on my java code

private void showMenu(View v, @MenuRes int menuRes) {
Context context = v.getContext();
popup = new PopupMenu(context, v);
popup.getMenuInflater().inflate(menuRes, popup.getMenu());

    int i = 0;
    for (String menuItemData : menuItemDataList) {
        popup.getMenu().add(Menu.NONE, i, Menu.NONE, menuItemData);
        i++;
    }
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            button.setText(menuItem.getTitle().toString());
            return true;
        }
    });
    popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
        @Override
        public void onDismiss(PopupMenu menu) {
            // Respond to popup being dismissed.
        }
    });
    // Show the popup menu.
    popup.show();
}
@saket
Copy link
Owner

saket commented Feb 22, 2024

cascade should be usable from Java. Can you share what have you tried so far?

@AymenBoukhari
Copy link
Author

cascade should be usable from Java. Can you share what have you tried so far?

i tried this but it just gives me the default menu do i need to change something in the xml files?

private void showMenu(View v, @MenuRes int menuRes) {
Context context = v.getContext();
popup = new CascadePopupMenu(context, v);
popup.inflate(R.menu.popup_menu);

    int i = 0;
    for (String menuItemData : menuItemDataList) {
        popup.getMenu().add(Menu.NONE, i, Menu.NONE, menuItemData);
        i++;
    }
    popup.setOnMenuItemClickListener(new androidx.appcompat.widget.PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            button.setText(item.getTitle().toString());
            return true;
        }
    });

    // Show the popup menu.
    popup.show();
}

@bouchrahmn
Copy link

i have the same problem

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