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
精彩评论