I got this problem where I have three if statements and every one of them has IF String == null or String == "" and even the getText doesn't give any value, these doesn't activate.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_two:
final String hei = h.getText().toString();
final String wei = w.getText().toString();
String waist = wc.getText().toString();
if (hei == null || wei == null ){
final Animation animationFadeIn = AnimationUtils.loadAnimation(this, R.anim.fadein);
checker.setText("Please, put your information in these spots!");
checker.startAnimation(animationFadeIn);
}
else if (waist == null){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Are you sure?");
builder.setMessage("If you let Waist circumference empty, we will ask it from you later.")
.setCancelable(true)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent i = new Intent(getApplicationContext(), number3.class);
i.putExtra("height" , hei);
i.putExtra("weight" , wei);
startActivity(i);
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
}
});
AlertDialog alert = builder.create();
alert.show();
}
else{
Log.d("BMI Height" , String.valueOf(wei));
Log.d("BMI Weight" , String.valueOf(hei));
Intent i = new Intent(getApplicationContext(), healthcalculator3.class);
i.putExtra("height" , hei);
i.putExtra("WC" , waist);
i.putExtra("weight" , wei);
startActivity(i);
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
}
And even if all those (waist, wei, hei) are null or not value set, it only activates the last ELSE and the machine thinks that they have some data/value.