Я работаю над викториной для Android. когда я запускаю его на эмуляторе, появляется первый вопрос, и я отвечаю на него. он перестал работать. а затем перезапустите с начала. я не знаю, где проблема в моем коде.
Я работаю над викториной для Android. когда я запускаю его на эмуляторе, появляется первый вопрос, и я отвечаю на него. он перестал работать. а затем перезапустите с начала. я не знаю, где проблема в моем коде.
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.question); /** * Configure current game and get question */ currentGame = ((CYKApplication)getApplication()).getCurrentGame(); currentQ = currentGame.getNextQuestion(); Button nextBtn1 = (Button) findViewById(R.id.answer1); nextBtn1.setOnClickListener(this); Button nextBtn2 = (Button) findViewById(R.id.answer2); nextBtn2.setOnClickListener(this); Button nextBtn3 = (Button) findViewById(R.id.answer3); nextBtn3.setOnClickListener(this); Button nextBtn4 = (Button) findViewById(R.id.answer4); nextBtn4.setOnClickListener(this); /** * Update the question and answer options.. */ setQuestions();
}
/** * Method to set the text for the question and answers from the current games * current question */ private void setQuestions() { //set the question text from current question String question = Utility.capitalise(currentQ.getQuestion()); TextView qText = (TextView) findViewById(R.id.question); qText.setText(question);
//set the available options List answers = currentQ.getQuestionOptions(); TextView option1 = (TextView) findViewById(R.id.answer1); option1.setText(Utility.capitalise(answers.get(0)));
@Override public void onClick(View arg0) { //Log.d("Questions", "Moving to next question");
if(!checkAnswer()) return;
/** * check if end of game */ if (currentGame.isGameOver()){ //Log.d("Questions", "End of game! lets add up the scores.."); //Log.d("Questions", "Questions Correct: " + currentGame.getRight()); //Log.d("Questions", "Questions Wrong: " + currentGame.getWrong()); Intent i = new Intent(this, EndgameActivity.class); startActivity(i); finish(); } else{ Intent i = new Intent(this, QuestionActivity.class); startActivity(i); finish(); } }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK : return true; }
return super.onKeyDown(keyCode, event); }
/** * Check if a checkbox has been selected, and if it * has then check if its correct and update gamescore */ private boolean checkAnswer() { String answer = getSelectedAnswer();