I am familiar with Actionscript programming, and I often used the "<=" (less than or equal to) or ">=" (greater than or equal to) operators.
However in Eclipse, I have been unable to use such operators. Here's my situation. Defined variable:
final EditText UserNumber = (EditText) findViewById(R.id.editText1); And here's the use:
if (UserNumber <= 10){ } I'm sure this is a very easy/quick fix but I have been unable to locate what should be used in this situation.
And this is the error I'm getting:
6The operator <= is undefined for the argument type(s) EditText, int
5 Answers
As the error clearly states, you can't compare an EditText instance to a number.
You probably want to get the EditText's value.
As a solution, use this instead
Integer.parseInt(UserNumber.getText().toString()); In your case, this works fine,
if((Integer.parseInt(UserNumber.getText().toString()) )<=10) { //Do what you want } 2You will first need to get the text from the edit text view, then if it is a Integer get the value from the string.
Integer.parseInt(UserNumber.getText().toString()); As mentioned above.
Integer.valueOf(UserNumber.getText().toString())<=10 1Dangerous bend! You cannot use <= etc to compare Java objects. You need to use a compareTo method if it is implemented. This goes especially for strings.