Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quickest way to get user input in Android

What's the fastest way for creating user input dialogs ? I could 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?

like image 355
Vincent Avatar asked Dec 10 '22 09:12

Vincent


1 Answers

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

like image 169
whirlwin Avatar answered Dec 30 '22 10:12

whirlwin