jeudi 31 août 2017

Java Android Studio, I get error on if statement [duplicate]

This question already has an answer here:

This is the error code questionNumber is red

if (inputText == questionNumber) {

            }

I need to test the input number exactly to questionNumber

This is the code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final TextView numbers = (TextView) findViewById(R.id.textView);
    final Random random = new Random();


    Button generate = (Button) findViewById(R.id.btnRandom);

    generate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String questionNumber = String.format("%04d",random.nextInt(10000));

            numbers.setText(questionNumber);

        }
    });

    Button btnOke = (Button) findViewById(R.id.btnOK);
    final EditText input = (EditText) findViewById(R.id.inputNumber);
    final String inputText = input.getText().toString();
    btnOke.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            if (inputText == questionNumber) {

            }
        }
    });
}

}

Aucun commentaire:

Enregistrer un commentaire