我有以下课程,需要向用户显示随机问题。
但是我的问题是,班级只显示一个问题,而不是连续提问。 如何重复用户问题以保持他们的!得分了? 见下图 -
public class Chooser extends ActionBarActivity implements View.OnClickListener {
int randomOne = 0;
int randomTwo = 0;
int problems = 0;
int sum = 0;
int userAnswer = 0;
int correct = 0;
int inCorrect = 0;
int userInput, result;
TextView question, response, answer, report;
EditText userNumber;
Button ans;
private Random add;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chooser);
question = (TextView) findViewById(R.id.question);
response = (TextView) findViewById(R.id.response);
answer = (TextView) findViewById(R.id.answers);
report = (TextView) findViewById(R.id.report);
userNumber = (EditText) findViewById(R.id.answer);
ans = (Button) findViewById(R.id.button);
ans.setOnClickListener(this);
add = new Random();
randomOne = add.nextInt(20);
randomTwo = add.nextInt(10);
Display();
}
public void Display() {
sum = randomOne + randomTwo;
question.setText(randomOne + " + " + randomTwo);
}
@Override
public void onClick(View v) {
userInput = Integer.parseInt(userNumber.getText().toString());
Log.e("getting user input", "" + userInput);
if (userInput == sum) {
response.append(" CORRECT! , You are the best \n");
correct++;
} else {
response.append("INCORRECT, The correct answer was :" + sum + "\n");
inCorrect++;
}
problems++;
}
}
答案 0 :(得分:1)
我不确定我理解你的问题,但假设你想要每次点击“提交”按钮时向用户显示不同的“问题”,你应该在点击按钮后调用“Display()”方法并生成通过将randomOne& randomTwo设置为nextInt(some_number)来设置新的随机数...希望这有用..