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

Jul 24, 2020
val input = EditText(requireContext())input.inputType = InputType.TYPE_CLASS_NUMBER // capture number onlyinput.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.

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.