Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Toast Notifications

Hi,

Doing the code challenge. The question is as follows :

Initialize the Toast variable using the static makeText() method of the Toast class. Use the β€˜this’ keyword for the first parameter, the text "All done!" for the second parameter, and the constant Toast.LENGTH_LONG for the third parameter.

My answer

Toast allDoneToast; Toast welcomeToast = Toast.makeText(this, "All done!", Toast.LENGTH_LONG);

Please help

4 Answers

Let's work through the problem together.

You are given:

Toast allDoneToast;

Then the first sentence reads:

"Initialize the Toast variable using the static makeText() method of the Toast class."

So it wants you to initialize the Toast variable that was given to you (allDoneToast). Note that it's telling you to use the "makeText()" method which is static. This let's you know that you don't initialize it like most other objects (aka: You don't use the 'new' keyword for statics) Which is done like this:

allDoneToast = Toast.makeText();

Then it tells you:

" Use the β€˜this’ keyword for the first parameter, the text "All done!" for the second parameter, and the constant Toast.LENGTH_LONG for the third parameter."

Which is pretty self explanatory.

allDoneToast = Toast.makeText(this, "All done!", Toast.LENGTH_LONG);

Which gives you the final answer of:

The answer is:

Toast allDoneToast;
allDoneToast = Toast.makeText(this, "All done!", Toast.LENGTH_LONG);

Keep coding!

just Toast.maketext

Thank You sir :)