Android Capture Input via Dialog Popup (Quick Simple Solution without Class or Layout file)

July 24, 2020
val input = EditText(requireContext())
input.inputType = InputType.TYPE_CLASS_NUMBER // capture number only
input.setText("1")
val builder = AlertDialog.Builder(requireContext())
    .setTitle("Scroll To Page")
    .setView(input)
    .setPositiveButton(android.R.string.ok) { dialog, whichButton ->
        val position = input.text.toString().toInt()
        // do scroll to page
    }
    .show()

If you need a more complicated view, you can use a layout file.

You can also create a reusable class.

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.