IF/ELSE statement validation issue

I have the following code: View.OnClickListener calcu = new View.OnClickListener() { public void onClick(View v) { double q; String d = ""; double factor = cpi[to] / cpi [from]; DecimalFormat decimalFormat = new DecimalFormat("0.##"); if (eNum.getText().toString().length() <= 0 || bFrom.getText() == "- Select a Year -" || bTo.getText() == "- Select a Year -") { if (eNum.getText().toString().length() <= 0) { d += "Enter Dollar Amount"; eNum.setTextColor(Color.RED); } if (bFrom.getText() == "- Select a Year -") { d += "Select a Year"; bFrom.setTextColor(Color.RED); } if (bTo.getText() == "- Select a Year -") { d += "Select a Year"; bTo.setTextColor(Color.RED); } } else { dollarAmount = factor * Double.parseDouble(eNum.getText().toString()); String value = Double.toString(dollarAmount); if (value.charAt(value.length() - 2) == '.') { value += "0"; } displayToast("Dollar: " + value); if (cpi[to] != cpi[from]) { double f, y; if (cpi[to] > cpi[from]) { f = cpi[to] / cpi [from]; y = to - from; } else { f = cpi[from] / cpi[to]; y = from - to; } q = Math.pow(f, 1/y); q = (q-1)*100.0; q = Math.round(q*100.0)/100.0; displayToast("Inflation: " + String.valueOf(decimalFormat.format(q))); } } } }; `displayToast()` is a function which displays the Toast message to the user. `eNum` is an `EditText` `bFrom` and `bTo` are `Buttons` What I want to happen when the onClick method is activated: 1. If the `eNum` is empty, I want to make the text color RED. 2. If the `bFrom` and `bTo` buttons text is `- Select a Year -`, I want to make the text color RED. 3. If #1 and #2 is not true than display the Toasts. **Right now when I click, nothing is happening**. How do I fix the above code to work correctly?
What is your question?

以上就是IF/ELSE statement validation issue的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏