lunes, 4 de febrero de 2013

Converting from Editable to int in android


How to converting from Editable to int in android


Problem:

Need to convert from Editable to int

Solution:

Integer.ParseInteger(R2.getText())

Source: stackoverflow

Prompt User Input with an AlertDialog


How to prompt User Input with an AlertDialog


Problem:

Need to ask you some information to user using an Alert Dialog:

Solution:

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

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

alert.show();

Source: Android Snippets