Addressing Edge Cases

If there are no more questions available, you must inform the user. This case is handled by the handleNoQuestions() method. First, you set the text and image to appropriate values, as follows:

TextSwitcher questionTextSwitcher =

(TextSwitcher) findViewById(R.id.TextSwitcher_QuestionText); questionTextSwitcher.setText(getResources().getText(R.string.no_questions)); ImageSwitcher questionlmageSwitcher =

(ImageSwitcher) findViewById(R.id.ImageSwitcher_QuestionImage); questionImageSwitcher.setImageResource(R.drawable.noquestion);

You should also take this opportunity to disable the Button controls:

Button yesButton =

(Button) findViewById(R.id.Button_Yes); yesButton.setEnabled(false);

Button noButton =

(Button) findViewById(R.id.Button_No); noButton.setEnabled(false);

When the application runs out of questions, the game screen looks as shown in Figure 12.5. The user is informed that there are no more questions available and is not allowed to press any of the Button controls. Instead, the user must press the Back button and return to the main menu.

FIGURE 12.5

The Been There, Done That! game screen when no questions are available.

Been There, Done Thatl

No more qùestiéns available. Try back' ' later. " .

0 0

Post a comment