mikepenz / MaterialDrawer

The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.
https://mikepenz.dev
Apache License 2.0
11.67k stars 2.05k forks source link

How to implement on item click listener in Java #2786

Closed panovvitalik closed 2 years ago

panovvitalik commented 2 years ago

About this issue

I'm trying to migrate from 6.1.2 to 9.0.1

My project is on Java.

In Kotlin I see an example:

// specify a click listener
slider.onDrawerItemClickListener = { v, drawerItem, position ->
    // do something with the clicked item :D
    false
}

In java I wrote below code (as Android studio was supposed to me):

slider.setOnDrawerItemClickListener(new Function3<View, IDrawerItem<?>, Integer, Boolean>() {
            @Override
            public Boolean invoke(View view, IDrawerItem<?> iDrawerItem, Integer integer) {
                switch ((int)iDrawerItem.getIdentifier()) {
                    case MENU_ITEM_LOGIN:
                        login();
                        break;
                }
                return false;
            }
        });

and this on click listener is never called. Where am I wrong? It only closes menu drawer - and thats all.

Details

mikepenz commented 2 years ago

Sadly there is no support for Java in the versions beyond v6.x, and many of the extensions and helper functions will only work in Kotlin projects.


https://github.com/mikepenz/MaterialDrawer#latest-releases-

Screenshot 2022-08-19 at 14 57 53

There's no plan to support Java anymore.

The only workaround could be to use Kotlin for the screens where you require it, and keep the rest of the app in Java.

panovvitalik commented 2 years ago

It's very sad to hear this :-(