vendredi 7 avril 2017

Android Studio if statement with OR (||) Function

I am creating a mobile application that updates users with the current score and final score in a football match. I want the textview displaying the score to show only the current or final score. I am having trouble with the if statement. I need one of the fields to contains something in order for a record to be created so I have:

if (!(et_currentgoals.getText().toString().isEmpty()) || !(et_finalgoals.getText().toString().isEmpty()){
}

Inside this if statement I was another that updates the textview with the correct values. So if the final number of goals was entered, the current goals are discarded. Would the best way be something like this:

if(!(et_finalgoals.getText().toString.isEmpty()){
tv_goals.setText(et_finalgoals.getText().toString();
}else{
tv_goals.setText(et_currentgoals.getText().toString();
}

Does this cover both scenarios or am I missing something?

Aucun commentaire:

Enregistrer un commentaire