[Android] AlertDialog with Edittext
2011-08-30 00:00
1 minute read
  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();  

就這樣XD

ref: http://www.androidsnippets.com/prompt-user-input-with-an-alertdialog


Back to posts


comments powered by Disqus