简体   繁体   中英

Android - When checking to see if text box length is longer or equal to 1 to then do something, it only does it if character length is 3 or more

if (checkBoxSlower.isChecked()) {
    if (editTextSF.getText().length() >= 1) {
        sf2[0] = (Integer.parseInt(editTextSF.getText().toString()));
        sf[0] = 1 + (sf2[0] / 100);
    }
    else {
        sf[0] = 1.35; // default - 1.35
    }
}
else if (checkBoxFaster.isChecked()) {
    if (editTextSF.getText().length() >= 1) {
        sf2[0] = (Integer.parseInt(editTextSF.getText().toString()));
        sf[0] = 1 - (sf2[0] / 100);
    }
    else {
        sf[0] = 0.65; // default - 0.65
    }
}

That's my code that i am referring to, the numbers only text box skips the if statement if it says 99 or lower, but with 100 it works, Can't find an answer online

your code is working. But it seems you're not considered one logical point.
result of this division sf2[0] / 100 is zero if sf2[0] < 100 . in the other hand when editTextSF.getText().length() >= 1 and editTextSF.getText().length() < 3 it means that your input number is between 0 to 99 that you assign it to sf2[0] . because of that sf[0] will be 1 either checkBoxSlower.isChecked() or checkBoxFaster.isChecked()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM