How can I set a long click listener on a MenuItem?
I tried this answer, but the method doesn\'t exist for me. Any solutions?
Code:
<
From massivemadness answer here is a slight variation to target a menu. I also don't think this is stable, it feels like a bodge but nest it in a try catch, keep calm and move on :)
if(navigationAdapter != null) {
navigationRecycler.post { // this line is important
for(index in 0 until navigationAdapter.itemCount) {
val item = navigationLayoutManager.findViewByPosition(index)
item?.setOnLongClickListener {
try{
Toast.makeText(this, "${nav_view.menu[index - 1 /*Number of children before your menu*/].title}!", Toast.LENGTH_SHORT).show()
true
} catch (e:Throwable){
false
}
}
}
}
}