+ Reply to Thread
Results 1 to 2 of 2

Thread: Alert box with text input and a button

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    28

    Alert box with text input and a button

    I am creating a simple application that will pop up an alert box , take an input from user and when
    user click ok it will operate on that input.
    So how can i do that ?

  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    27
    You will need to use the AlertDialog.Builder
    Code:
    AlertDialog.Builder AD = new AlertDialog.Builder(this);
    
    AD.setTitle("Message Title");
    AD.setMessage("Message Text");
    
    // Set an EditText view to get user input 
    final EditText input = new EditText(this);
    AD.setView(input);
    
    AD.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
      String value = input.getText();
      // Do something with the text input!
      }
    });
    
    AD.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int whichButton) {
        // Canceled.
      }
    });
    
    AD.show();

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts