jeudi 29 novembre 2018

Check if a number inputted in an "EditText" is in an array - Android Studio Java

I want to know if a number that a user inputted into an "EditText" actually exists inside an array, here is my current code:

 final String[] numberArray = {("1"), ("2"), ("3"), ("4"), ("5")};


public void startGame(View v) {

    if (Arrays.asList(agesArray).contains((text))) {

        Outputs1.setText("You typed in: " + text + ", which is correct!");

    } else {

        Outputs1.setText("Please type in a number 1-5.");

When the users type in the number, it checks if the number exists in an array by using an If-Statement, and if it does it displays a message.

Sadly, this does not work, and the other questions and answers also did not work either.

Any response will be great.

Aucun commentaire:

Enregistrer un commentaire