Skip to content

Instantly share code, notes, and snippets.

@igordeoliveirasa
Created February 20, 2015 13:43
Show Gist options
  • Save igordeoliveirasa/9d414f5772c09d8bfb28 to your computer and use it in GitHub Desktop.
Save igordeoliveirasa/9d414f5772c09d8bfb28 to your computer and use it in GitHub Desktop.
Android Alert With Text Input
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("Title");
alert.setMessage("Message");
// Set an EditText view to get user input
final EditText input = new EditText(context);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString();
// Do something with value!
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment