Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MenuItem.SetOnActionExpandListener() with Kotlin

Like basically everything with Kotlin Android Development, I am having trouble finding an example of how to utilize the MenuItem.SetOnActionExpandListener() in Kotlin.

My menuItem is a search action, and I need to trigger a function whenever the user closes the search. However, when searching how to do all of this, the only examples I find are in Java with zero information about how to do it in Kotlin...

I am attempting to use this solution, but I can't seem to figure out how to do this with Kotlin...

How do I convert that solution into Kotlin syntax?

like image 252
BlondeSwan Avatar asked Sep 06 '25 09:09

BlondeSwan


1 Answers

Here's one way:

menuItem.setOnActionExpandListener(object : MenuItem.OnActionExpandListener {
  override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
    // TODO: do something...
    return true
  }

  override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
    // TODO: do something...
   return true
  }
})
like image 83
Jorge Gil Avatar answered Sep 08 '25 01:09

Jorge Gil