Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My app is writing inputStream to string, then string to textView. Under that I controll my UI animations with if statements. Now I don`t know how to make if statement: if (BTtext => 100 && BTtext <=350)

Values from 100 to 350 are for seekbarposition adjustment. I also have other values that need to be ignored in that case. I had tryed:

if(strInput > lowervol && strInput < uppervol) {
}

strInput is my inputStream. lowervol & uppervol are created as so:

    final static String lowervol = "99";
    final static String uppervol = "351";

If I do it like that I get:

error: bad operand types for binary operator '>'
first type:  String
second type: String

error: bad operand types for binary operator '<'
first type:  String
second type: String

How can this be done? Thank you


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
592 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can't compare actual strings with > or <. What you actually want to compare in your case is the number contained in the string, not the string itself.

For that, your constants should probably be stored as int:

static final int LOWER_VOL= 99;
static final int UPPER_VOL= 351;

And before comparison, your strInput should be converted to int aswell. Something like this:

int inputValue = Integer.parseInt(strInput); // parsing exceptions to be handled here
if(inputValue > lowervol && inputValue < uppervol) {
    // do stuff
}

When adapting the naming convention of the constants from above, the final snippet will look like this:

int inputValue = Integer.parseInt(strInput); // parsing exceptions to be handled here
if(inputValue > LOWER_VOL && inputValue < UPPER_VOL) {
    // do stuff
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...