我正在编写一个简单的测验应用程序,类似于流行的应用程序谁想成为百万富翁?一切都很顺利,直到用户回答第十个问题后我无法完成操作。我真正想要的是,在用户回答 10 个问题后,我会显示一条消息,说他们已经达到了第 10 个问题,但我无法做到这一点。
public class MainActivity extends Activity implements View.OnClickListener{
TextToSpeech t1;
Button btn_one, btn_two, btn_three, btn_four;
TextView tv_question;
private Question question = new Question();
private String answer;
private int questionLength = question.questions.length;
Random random;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
random = new Random();
btn_one = (Button)findViewById(R.id.btn_one);
btn_one.setOnClickListener(this);
btn_two = (Button)findViewById(R.id.btn_two);
btn_two.setOnClickListener(this);
btn_three = (Button)findViewById(R.id.btn_three);
btn_three.setOnClickListener(this);
btn_four = (Button)findViewById(R.id.btn_four);
btn_four.setOnClickListener(this);
tv_question = (TextView)findViewById(R.id.tv_question);
NextQuestion(random.nextInt(questionLength));
final String input = tv_question.getText().toString()
}
public void onPause() {
if (t1 != null) {
t1.stop();
t1.shutdown();
}
super.onPause();
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btn_one:
if(btn_one.getText() == answer){
Toast.makeText(MainActivity.this, "You Are Correct", Toast.LENGTH_SHORT).show();
NextQuestion(random.nextInt(questionLength));
}else{
GameOver();
}
婷婷同学_
holdtom
相关分类