5.6.9. Anonymous Inner Class That Implements OnClickListener

Lines 91–98 (Fig. 5.27) registered guessButtonListener (Fig. 5.33) as the event-handling object for each guess Button. Instance variable guessButtonListener refers to an anonymous inner class object that implements interface OnClickListener to respond to Button events. The method receives the clicked Button as parameter v. We get the Button’s text (line 259) and the parsed country name (line 260), then increment totalGuesses.

If the guess is correct (line 263), we increment correctAnswers. Next, we set the answerTextView’s text to the country name and change its color to the color represented by the constant R.color.correct_answer (green), and we call our utility method disableButtons ...

Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.