android kotlin pop up menu code example

Example: android popup menu kotlin

val popupMenu: PopupMenu = PopupMenu(this,button)  
           popupMenu.menuInflater.inflate(R.menu.popup_menu,popupMenu.menu)  
           popupMenu.setOnMenuItemClickListener(PopupMenu.OnMenuItemClickListener { item ->  
                    when(item.itemId) {  
                    R.id.action_crick ->  
                        Toast.makeText(this@MainActivity, "You Clicked : " + item.title, Toast.LENGTH_SHORT).show()  
                    R.id.action_ftbal ->  
                        Toast.makeText(this@MainActivity, "You Clicked : " + item.title, Toast.LENGTH_SHORT).show()  
                    R.id.action_hockey ->  
                        Toast.makeText(this@MainActivity, "You Clicked : " + item.title, Toast.LENGTH_SHORT).show()  
                }  
                true  
           })  
           popupMenu.show()