Skip to content

Instantly share code, notes, and snippets.

@k0siara
Created November 5, 2022 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k0siara/317847e60ec793b1c7824b69cb4cf8aa to your computer and use it in GitHub Desktop.
Save k0siara/317847e60ec793b1c7824b69cb4cf8aa to your computer and use it in GitHub Desktop.
MyFragment.kt
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