mercredi 28 décembre 2016

Android if-else equals not working

I have trouble with this simple code. The comparison with the strings do not seem to work, and I get a different result than hoped. I inserted a Toast for each cycle, to compare the result. What's wrong.

if (shared.equals("AZ") || shared.equals("") && shared1.equals("insieme") || shared1.equals("")) {
         visualizza = 3;
        Toast.makeText(getActivity(), visualizza + " " + shared + " " + shared1,
                Toast.LENGTH_SHORT).show();
    } else if (shared.equals("ZA") && shared1.equals("insieme")) {
        visualizza = 4;
        Toast.makeText(getActivity(), visualizza + " " + shared + " " + shared1,
                Toast.LENGTH_SHORT).show();
     } else if (shared.equals("AZ") && shared1.equals("default")) {
        visualizza = 1;
        Toast.makeText(getActivity(), visualizza + " " + shared + " " + shared1,
                Toast.LENGTH_SHORT).show();
     } else if (shared.equals("ZA") && shared1.equals("default")) {
        visualizza = 2;
        Toast.makeText(getActivity(), visualizza + " " + shared + " " + shared1,
                Toast.LENGTH_SHORT).show();
     }

Aucun commentaire:

Enregistrer un commentaire