Reputation: 866
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
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
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