saket / cascade

Nested popup menus with smooth height animations for Android
https://saket.github.io/cascade
Apache License 2.0
2.02k stars 67 forks source link

is this code works in java? #52

Open AymenBoukhari opened 7 months ago

AymenBoukhari commented 7 months ago

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

<?xml version="1.0" encoding="utf-8"?>

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 commented 7 months ago

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

AymenBoukhari commented 7 months ago

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 commented 7 months ago

i have the same problem