在Android上,在最后一个问题之后("是谁的Flavie?"),我想要第一个问题("谁是汤姆?")当我点击按钮
时再次显示preventDefault()
答案 0 :(得分:1)
复杂的方法
final String questions[] = {"Who's Tom?", "Who's Luca?", "Who's Flavie?"}
final String answers[] = {"American", "Italian", "French"}
// display question
answer_question.setOnClickListener(new View.OnClickListener() {
int CurrentQuestionIndex = 0;
public void onClick(View v) {
// make below line changes
ask_question.setText(question[(++CurrentQuestionIndex) % (questions.length-1)]);
// discuss question versus answer
EditText editText = (EditText) findViewById(R.id.tvReponseF);
if(editText.getText().toString().equals(answers[CurrentQuestionIndex]))
{
alertMessageRight();
} else {
alertMessageFalse();
}
}
});
简单的方法
final String questions[] = {"Who's Tom?", "Who's Luca?", "Who's Flavie?"}
final String answers[] = {"American", "Italian", "French"}
// display question
answer_question.setOnClickListener(new View.OnClickListener() {
int CurrentQuestionIndex = 0;
public void onClick(View v) {
ask_question.setText(question[CurrentQuestionIndex]);
// discuss question versus answer
EditText editText = (EditText) findViewById(R.id.tvReponseF);
if(editText.getText().toString().equals(answers[CurrentQuestionIndex]))
{
alertMessageRight();
} else {
alertMessageFalse();
}
if(CurrentQuestionIndex++ == questions.length-1){
CurrentQuestionIndex =0;
}
}
});