Skip to content

Commit

Permalink
feat : Extension function for listItem in AlertDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
neeldoshii authored and lukstbit committed Feb 27, 2024
1 parent 579eb0f commit 85f0c4a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/utils/AlertDialogFacade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,14 @@ fun AlertDialog.getInputField() = getInputTextLayout().editText!!
/** @see AlertDialog.getButton */
val AlertDialog.positiveButton: Button
get() = getButton(DialogInterface.BUTTON_POSITIVE)

/**
* Extension function for AlertDialog.Builder to set a list of items.
* @param items The items to display in the list.
* @param onClick A lambda function that is invoked when an item is clicked.
*/
fun AlertDialog.Builder.listItems(items: List<CharSequence>, onClick: (dialog: DialogInterface, index: Int) -> Unit): AlertDialog.Builder {
return this.setItems(items.toTypedArray()) { dialog, which ->
onClick(dialog, which)
}
}

0 comments on commit 85f0c4a

Please sign in to comment.