Prompt User Input in AlertDailog in Android

by Sasikumar 2014-01-08 21:16:10

To get user input in alert dialog :
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Dialog Title");
alert.setMessage("Message to display in dialog");

// Define a EditText 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();
// Process with the received value
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Dialog has been cancelled
}
});

alert.show();
616
like
0
dislike
0
mail
flag

You must LOGIN to add comments