jeudi 10 novembre 2016

Get random numbers again and again if answer given by user is wrong

I am developing a simple dialog box which has two textviews one edittext and one submit button. Now what i want is to put some random numbers in those two textviews and multiply them. User has to give correct answer to finish the application. If he failed to do so then again next random numbers generated and so on until the user gives the right answer.

I have manage to do so all work almost but when user gives the wrong answer then i am unable to generate next two random numbers and so on. My code for this dialog box is:

final TextView t1 = (TextView)dialog1.findViewById(R.id.textView2);
final TextView t2= (TextView)dialog1.findViewById(R.id.textView);
final EditText editText = (EditText) dialog1.findViewById(R.id.edit1);
TextView submit = (TextView)dialog1.findViewById(R.id.submit);

final int number = (new Random().nextInt(100));
final int number1 = (new Random().nextInt(100));
t1.setText(String.valueOf(number));
t2.setText(String.valueOf(number1));

submit.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        String a = editText.getText().toString();
        if (Integer.parseInt(a) == number*number1) {
         ActivityA.this.finish();
        } else {

        }
    }

});

Please help me to write else part so that if user gives wrong answer then next numbers generated and if after few wrong answers the user gives right answer then the app finishes. Help needed

Aucun commentaire:

Enregistrer un commentaire