Yevgeny Simkin
Yevgeny Simkin

Reputation: 28379

is there no pre-baked Android Dialog prompt?

I just realized that I don't see a way to collect a string from the user in a simple, pre-packaged Dialog prompt. Am I overlooking something or do I really need to write a custom Dialog to perform this function?

Upvotes: 0

Views: 106

Answers (3)

Tim
Tim

Reputation: 6712

Basically I would use an AlertDialog and create a new EditText. Hand it to the Dialog with .setView and handle the text in the onClick-Events.

  final EditText prompt = new EditText(this);
  AlertDialog.Builder builder = new Builder(this);
  builder.setTitle("My fancy title");
  builder.setView(prompt);
  builder.setPositiveButton("Ok", new OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
      String myText = prompt.getText().toString();
    }
  });
  AlertDialog promptDialog = builder.create();
  promptDialog.show();

Upvotes: 2

Dany Y
Dany Y

Reputation: 7041

check this link

http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application

the idea is to use dialog.setContentView(), and make ur own layout there

Upvotes: 3

user
user

Reputation: 87064

You don't have this type of Dialog in the SDK but it is pretty simple to make one with the AlertDialog and his setView() method.

Upvotes: 1

Related Questions