Wednesday, June 19, 2013

[android help] Showing a message dialog in Android


Showing a message dialog in Android



Today I've started to build my first android app, I'm used to work with Java but there are something that I don't know how to do in my android app. It's a simple calculator, and I'm trying to show a message dialog if the user inputs an invalid number.


Here's my code:



public void calculate(View v) {
EditText theNumber = (EditText) findViewById(R.id.number);
int num;
try {
num = Integer.parseInt(theNumber.getText().toString());
} catch (NumberFormatException e) {
//missing code here
}
}


In Java SE I'd just do this:



public void calculate(View v) {
EditText theNumber = (EditText) findViewById(R.id.number);
int num;
try {
num = Integer.parseInt(theNumber.getText().toString());
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog("Invalid input");
}
}


How can I do that in android?



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...