java - Android Studio if statement with OR (||) Function -
i creating mobile application updates users current score , final score in football match. want textview displaying score show current or final score. having trouble if statement. need 1 of fields contains in order record created have:
if (!(et_currentgoals.gettext().tostring().isempty()) || !(et_finalgoals.gettext().tostring().isempty()){ }
inside if statement updates textview correct values. if final number of goals entered, current goals discarded. best way this:
if(!(et_finalgoals.gettext().tostring.isempty()){ tv_goals.settext(et_finalgoals.gettext().tostring(); }else{ tv_goals.settext(et_currentgoals.gettext().tostring(); }
does cover both scenarios or missing something?
having second if
block inside first work, there's simpler way.
this single if
work.
if (!et_finalgoals.gettext().tostring.isempty()) { tv_goals.settext(et_finalgoals.gettext().tostring(); } else if (!et_currentgoals.gettext().tostring.isempty()) { tv_goals.settext(et_currentgoals.gettext().tostring(); }
in other words, these 2 blocks equivalent
if (a || b) { if (a) { // } else { // b } } if (a) { // } else if (b) { // b }
if i'm understanding correctly, executing additional code inside of first if statement, after setting tv_goals
text. now, can check text of tv_goals
.
if (!tv_goals.gettext().tostring.isempty()) { // additional code }
if case, ends being same amount of code original solution. should pick whichever way more clear you.
Comments
Post a Comment