Created
August 17, 2020 20:40
-
-
Save polson/83af8608bafb4705d63996d6d3b1510a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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