Created
November 5, 2022 21:08
-
-
Save k0siara/317847e60ec793b1c7824b69cb4cf8aa to your computer and use it in GitHub Desktop.
MyFragment.kt
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 MyFragment : Fragment(R.layout.my_layout) { | |
fun onSomeAction() { | |
// Code A | |
showDialog( | |
onOkClicked = { ... }, | |
onCancelClicked = { ... } | |
) | |
// Code B | |
} | |
private fun showDialog( | |
onOkClicked: () -> Unit, | |
onCancelClicked: () -> Unit | |
) { | |
AlertDialog.Builder(context) | |
.setPositiveButton(R.string.ok) { dialog, id -> | |
onOkClicked() | |
} | |
.setNegativeButton(R.string.cancel) { dialog, id -> | |
onCancelClicked() | |
} | |
.create() | |
.show() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment