mikepenz/MaterialDrawer

onDrawerItemClickListener Not invoked when item clicked

Chullian opened this issue · 4 comments

About this issue

binding.homeDrawer.apply {
            itemAdapter.add(
                PrimaryDrawerItem().apply {
                    nameText = "HOME"; identifier = 1
                },
                PrimaryDrawerItem().apply {
                    nameText = "LOGOUT"; identifier = 2
                })
             onDrawerItemClickListener = { _,drawerItem, _ ->
                when  {
                    drawerItem.identifier == 1L -> {
                        Toast.makeText(this@HomeActivity, "clicked home", Toast.LENGTH_SHORT).show()
                    }
                    drawerItem.identifier == 2L -> {
                        Toast.makeText(this@HomeActivity, "clicked logout", Toast.LENGTH_SHORT).show()
                    }
               }}
  }

this is my drawer creation and click listener, but the click event is not getting triggered. is there anything wrong here?

@Chullian tried your code, which won't compile as the when is not exhaustive and the boolean return value is missing.

binding.slider.apply {
            itemAdapter.add(
                PrimaryDrawerItem().apply {
                    nameText = "HOME"; identifier = 1
                },
                PrimaryDrawerItem().apply {
                    nameText = "LOGOUT"; identifier = 2
                })
            onDrawerItemClickListener = { _, drawerItem, _ ->
                when {
                    drawerItem.identifier == 1L -> {
                        Toast.makeText(this@DrawerActivity, "clicked home", Toast.LENGTH_SHORT).show()
                    }
                    drawerItem.identifier == 2L -> {
                        Toast.makeText(this@DrawerActivity, "clicked logout", Toast.LENGTH_SHORT).show()
                    }
                    else -> {}
                }
                false
            }
        }
        ```

after fixing this, the listener is correctly triggered though in the sample. 

I'd assume either the return of the listener is off, or maybe the `DrawerLayout` itself is not clickable or such. 

@mikepenz

maybe the DrawerLayout itself is not clickable or such.

means? is there any other step I am missing here? because when i added else and return statement it still same

Just mentioning guesses, as noted above. using the sample code, everything works perfectly fine if used in the sample.

If you have a full compilable runnable sample to showcase the issue, I can have a closer look.

closing this issue since i have found the problem. It was , a viewGroup below the drawerSlider view. Thank you Mike for this amazing library