开发者

Quickest way to get user input in Android

开发者 https://www.devze.com 2023-02-28 04:03 出处:网络
What\'s the fastest way for creating user input dialogs ? I coul开发者_运维百科d make different activitys everytime I need user input put that looks like overkill in my case.I just need a small amount

What's the fastest way for creating user input dialogs ? I coul开发者_运维百科d make different activitys everytime I need user input put that looks like overkill in my case. I just need a small amount of popups in different screens for a user interface.

Can someone point me in the right direction?


AlertDialog.Builder from the API. Here is an example:

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().toString();
  // Do something with value!
  }
});

alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog, int whichButton) {
    // Canceled.
  }
});

alert.show();

It's a convenient way of retrieving user input.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消