Skip to content

Instantly share code, notes, and snippets.

@tedhagos
Created September 28, 2018 14:58
Show Gist options
  • Save tedhagos/0c71980dd9f3c98a90e74677c72f9ada to your computer and use it in GitHub Desktop.
Save tedhagos/0c71980dd9f3c98a90e74677c72f9ada to your computer and use it in GitHub Desktop.
Using when in an Android app
class MainActivity : AppCompatActivity() {
val Log = Logger.getLogger(MainActivity::class.java.name)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
Log.info("onCreateOptionsMenu")
menu?.add("File")
menu?.add("Exit")
return super.onCreateOptionsMenu(menu)
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item?.toString()) {
"File" -> {
Log.info("LOG File menu")
}
"Exit" -> {
Log.info("LOG Exit menu")
}
}
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment