Android popup dialog with edittext

Android-popup-dialog-with-edittext-featured.jpg

Prompt User Input with an AlertDialog

Android popup dialog with edittext1 Android popup dialog with edittext

This code creates an input-dialog with AlertDialog.Builder where a user can enter text in an EditText field and press on “Ok” and “Cancel”.

raw ·
copy
· download
AlertDialog.Builder alert = new AlertDialog.Builder(this);

alert.setTitle(“Title”);
alert.setMessage(“Message”);

// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);

alert.setPositiveButton(“Ok”, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText();
// Do something with value!
}
});

alert.setNegativeButton(“Cancel”, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});

alert.show();

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)