Skip to content

Instantly share code, notes, and snippets.

@Wajahat-Jawaid
Created November 2, 2022 13:31
Show Gist options
  • Save Wajahat-Jawaid/a2849554c1f930488fb56576628b37c2 to your computer and use it in GitHub Desktop.
Save Wajahat-Jawaid/a2849554c1f930488fb56576628b37c2 to your computer and use it in GitHub Desktop.
object DialogUtils {
fun showAlertDialog(
context: Context,
@StringRes title: Int,
@StringRes message: Int,
@StringRes buttonText: Int,
action: () -> Unit
) {
val resources = context.resources
AlertDialog.Builder(context)
.setTitle(resources.getString(title))
.setMessage(resources.getString(message))
.setCancelable(false)
.setPositiveButton(resources.getString(buttonText)) { dialog, _ ->
action.invoke()
dialog.dismiss()
}
.show()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment