Note that there are some explanatory texts on larger screens.

plurals
  1. POIf statement constantly activating in android
    primarykey
    data
    text
    <p>I am working on some code that will allow the program to check if the user has entered a name and a birth day and decide if the birthday is today and play happy birthday. However while I have managed to get the program to use the correct date and play the songs the if statements do not seem to be working properly. When ever I enter the current date as the birthday the happy birthday song always starts up even when the name box is empty and it should ask for your name. This only happens when the birthday textbox and the current day match, so could anyone help me to get my if statement working correctly. Here is my if statement code.</p> <pre><code>if((btn==v) &amp;&amp; (name.getText().toString()!="") &amp;&amp; (bday.getText().toString()!="") &amp;&amp; (bday.getText().toString().equals(formatdate))){ String msg1 = "Today is " + sdf.format(cdate.getTime()) + ". Happy Birthday, " + name.getText() + "!"; toast = Toast.makeText(this, msg1, Toast.LENGTH_SHORT); toast.show(); //Context context = null; mp.start(); //mp.stop(); response.setText(msg1); }else if(btn==v &amp;&amp; name.getText().toString().equals("") &amp;&amp; bday.getText().toString()!=""){ String msg3 = "Please enter your name."; toast = Toast.makeText(this, msg3, Toast.LENGTH_SHORT); toast.show(); mp.stop(); response.setText(msg3); }else if(btn==v &amp;&amp; name.getText().toString()!="" &amp;&amp; bday.getText().toString().equals("")){ String msg4 = "Please enter your birthday."; toast = Toast.makeText(this, msg4, Toast.LENGTH_SHORT); toast.show(); response.setText(msg4); }else if(btn==v &amp;&amp; name.getText().toString().equals("") &amp;&amp; bday.getText().toString().equals("")){ String msg5 = "Please enter your name and birthday."; toast = Toast.makeText(this, msg5, Toast.LENGTH_SHORT); toast.show(); response.setText(msg5); }else{ String msg2 = "Today is " + formatdate + ". Sorry today is not your birthday."; toast = Toast.makeText(this, msg2, Toast.LENGTH_SHORT); toast.show(); response.setText(msg2); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload