banner



Get Text From Edittext Android Kotlin

Today we are going to talk over how to show an alert dialog with an input field (EditText) in Android Kotlin. In this article, you will learn a lot about an AlertDialog.

Description

Actually Android doesn't have the built-in dialog to do this. Fortunately, this is but a little extra piece of work on meridian of creating a standard alert dialog box. All y'all need to practice is create the Edit Text for the user to enter the data and configure it as a view of the warning dialog box. If required, yous can customize the blazon of input allowed using setInputType, if you lot demand.

If you tin can use the form fellow member variable, y'all tin can only prepare the variable to the value for Edit Text. It remains unchanged after clearing the dialog box.

Show Alert Dialog With an Input Field

Within Your Form:

          private String m_Text = "";        

Where ever you want to evidence an alert dialog with input box, you can apply the following method

Lawmaking

          fun showdialog(){         val builder: AlertDialog.Builder = android.app.AlertDialog.Builder(this)         builder.setTitle("Championship")  // Set upward the input         val input = EditText(this) // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text         input.setHint("Enter Text")         input.inputType = InputType.TYPE_CLASS_TEXT         builder.setView(input)  // Set up upward the buttons         builder.setPositiveButton("OK", DialogInterface.OnClickListener { dialog, which ->             // Here you lot go get input text from the Edittext             var m_Text = input.text.toString()         })         architect.setNegativeButton("Cancel", DialogInterface.OnClickListener { dialog, which -> dialog.cancel() })          builder.show()     }        

Press Alt + Enter to import AlertDialog and Builder in your Activeness or Fragment. In the in a higher place lawmaking beginning, we have created a Builder object of type AlertDialog.Builder(). So nosotros just take to create the EditText object and assign it to the Builder. We can also set the positive or negative buttons in the dialog if required. Finally, call builder.testify() method to show the dialog.

That's It. This is how to show alert dialog with an input field in Android Kotlin

If you lot have any questions, feel costless to ask in the comments section below.

Side by side Commodity

Get Full-Screen Size Including Status Bar & Navigation Bar – Android

Get Text From Edittext Android Kotlin,

Source: https://handyopinion.com/show-alert-dialog-with-an-input-field-edittext-in-android-kotlin/

Posted by: lopezdecul1995.blogspot.com

0 Response to "Get Text From Edittext Android Kotlin"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel