ronash
ronash

Reputation: 866

Opening an input dialog in Android

I would like to open at a certain point an input dialog, whose input I would be able to store and use it later. All examples I found on the Internet were pretty advanced, and I suppose they weren't as simple as I want it to be - I just need something similar to Java's :

String name = JOptionPane.showInputDialog("Enter your name");

Holding the input for later calculations is also important for me.

Thank you in advance.

Upvotes: 4

Views: 10086

Answers (2)

shihpeng
shihpeng

Reputation: 5381

Try the following code snippet. Main.this is the Activity reference.

// Set an EditText view to get user input 
final EditText input = new EditText(Main.this);

new AlertDialog.Builder(Main.this)
    .setTitle("Update Status")
    .setMessage(message)
    .setView(input)
    .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int whichButton) {
             editable = input.getText(); 
             // deal with the editable
         }
    })
    .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int whichButton) {
             // Do nothing.
         }
    }).show();

Upvotes: 7

the100rabh
the100rabh

Reputation: 4147

Nope there is none similar built in Android. But you can look for third party libraries like the one at http://www.basic4ppc.com/android/help/dialogs.html#inputdialog

Upvotes: 0

Related Questions