mardi 29 juin 2021

My Toast only goes through else statement Android Java

Still a beginner in Android development. I'm trying to create a simple 'score results' app where the user has to enter their score and their results appear as a toast accordingly. The problem is my Toast only goes for an else statement regardless of what score the user entered. What am I doing so wrong? Please help.

int score = 100;

public void checkResults (View view){

    Log.i("Results","Button Tapped");

    Button button = (Button) findViewById(R.id.button);

    TextView editTextNumber = (TextView) findViewById(R.id.editTextNumber);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(score < 29){

                Toast.makeText(getApplicationContext(), "You got an F", Toast.LENGTH_SHORT).show();
            }
            else if (score >= 30 && score <= 39){

                Toast.makeText(getApplicationContext(), "You got E", Toast.LENGTH_SHORT).show();
            } else {

                Toast.makeText(getApplicationContext(), "You failed", Toast.LENGTH_SHORT).show();
            }
        }
    });


}

Aucun commentaire:

Enregistrer un commentaire