android - Get random numbers again and again if answer given by user is wrong -
i developing simple dialog box has 2 textviews 1 edittext , 1 submit button. want put random numbers in 2 textviews , multiply them. user has give correct answer finish application. if failed again next random numbers generated , on until user gives right answer.
i have manage work when user gives wrong answer unable generate next 2 random numbers , on. code 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 = edittext.gettext().tostring(); if (integer.parseint(a) == number*number1) { activitya.this.finish(); } else { } } });
please me write else part if user gives wrong answer next numbers generated , if after few wrong answers user gives right answer app finishes. needed
int number,number1;// declare before oncreate number = (new random().nextint(100)); 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 = edittext.gettext().tostring(); if (integer.parseint(a) == number*number1) { activitya.this.finish(); } else { //regenerate random numbers. number = (new random().nextint(100)); number1 = (new random().nextint(100)); t1.settext(string.valueof(number)); t2.settext(string.valueof(number1)); edittext.settext(null); } } });
Comments
Post a Comment