Skip to content

Instantly share code, notes, and snippets.

@polson
Created August 17, 2020 20:40
Show Gist options
  • Save polson/83af8608bafb4705d63996d6d3b1510a to your computer and use it in GitHub Desktop.
Save polson/83af8608bafb4705d63996d6d3b1510a to your computer and use it in GitHub Desktop.
class BetterActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val button = findViewById<Button>(R.id.button)
button.setOnClickListener { showBetterDialog() }
val normalButton = findViewById<Button>(R.id.normalButton)
normalButton.setOnClickListener { launchNormalActivity() }
}
private fun launchNormalActivity() {
startActivity(Intent(this, NormalActivity::class.java))
}
private fun showBetterDialog() {
showDialogFragment {
title("Better Dialog")
message("This is a better dialog")
positiveButtonText("Continue")
negativeButtonText("Go back")
positiveButtonAction { showPositiveToast() }
negativeButtonAction { showNegativeToast() }
}
}
private fun showNegativeToast() =
Toast.makeText(this, "Negative button", Toast.LENGTH_SHORT).show()
private fun showPositiveToast() =
Toast.makeText(this, "Positive button", Toast.LENGTH_SHORT).show()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment