[Android] Show AlertDialog with EditText.

public void showDialogWithEditText() {
  AlertDialog.Builder alert = new AlertDialog.Builder(this);

  alert.setTitle("Server Message");
  alert.setMessage("Set Server 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().toString();
    
   }
  });

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

  alert.show();
  
 }
This method will show alertdialog with EditText.You can use "value" variable as required.

Comments

Popular posts from this blog

Fatal: LoadModule: error loading module 'mod_sql_mysql.c'

Regular Expression Route Constraints And Route Names in Laravel 5.4