Skip to content

Instantly share code, notes, and snippets.

@vahids
Created October 26, 2017 13:18
Show Gist options
  • Select an option

  • Save vahids/f3a5c68ba11ff3b231936f83e4e060c3 to your computer and use it in GitHub Desktop.

Select an option

Save vahids/f3a5c68ba11ff3b231936f83e4e060c3 to your computer and use it in GitHub Desktop.
My First Kotlin class
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
configureViewElements()
}
private fun configureViewElements() {
configureSubmitButton()
}
private fun configureSubmitButton() {
val submit = findViewById<Button>(R.id.submitFormBtn)
submit.setOnClickListener {
this.showMessage("Submiting form...", true)
}
}
private fun showMessage(msg: String, darkBackground: Boolean) {
val toast = Toast.makeText(this@MainActivity, msg, Toast.LENGTH_SHORT)
if (darkBackground) {
toast.view.setBackgroundColor(Color.GRAY)
}
toast.show()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment