Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1
Making Toasts

Making Toasts


Now to make the buttons fully armed and operational. You are going to have a press of each button
trigger a pop-up message called a toast. A toast is a short message that informs the user of something
but does not require any input or action. You are going to make toasts that announce whether the user
answered correctly or incorrectly (Figure 1.14).


Figure 1.14  A toast providing feedback


First, return to strings.xml and add the string resources that your toasts will display.


Listing 1.11  Adding toast strings (strings.xml)



GeoQuiz
Canberra is the capital of Australia.
True
False
Correct!
Incorrect!

To create a toast, you call the following method from the Toast class:


public static Toast makeText(Context context, int resId, int duration)

Free download pdf