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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Mohammad Rahman](https://secure.gravatar.com/avatar/b7ad0bec164e5b11bec1786c546dcda4?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Mohammad Rahman
1,168 PointsToast same as popup?
Am i correct to say Toast is same as popup in Java? I mean if I want to show a popup message in android....
thanks
2 Answers
![Kevin Faust](https://uploads.teamtreehouse.com/production/profile-photos/4112242/micro_python-programming-language.jpg)
Kevin Faust
15,353 Pointsit's actually a bit complicated and it's something you will do later on in the track. I can show you quickly show you how a basic pop up is formed.
Let's look at this:
//this popup box class is called AlertDialogFragment
public class AlertDialogFragment extends DialogFragment { // must extend this class
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) { //when we make a dialog, run this
Context context = getActivity();
//create a new AlertDialog.Builder which is what we call to create a dialog box
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setTitle("title here") //set a title
.setMessage("some message text") //set a message
//set the button text. the null means that when the popup box is closed, nothing will happen
.setPositiveButton("button text", null);
return builder.create(); //create the dialog box
}
}
I added some comments above to give a brief breakdown. this'll generally be what you need when creating a basic pop up box. This will be created in a separate class
In our main, we would use something like this. Usually in a method so we can call popup boxes easily anywhere in our code:
AlertDialogFragment dialog = new AlertDialogFragment();
dialog.show(getFragmentManager(), "error_dialog");
We create the new popup box object. and then we run the show() method.
We pass in two things: getFragmentManager() and just some text to describe the popup box. this will not be shown
Those are just the two parameters we generally will always pass in
The android site has a nice little tutorial on popup boxes if you wanna learn more:
http://developer.android.com/guide/topics/ui/dialogs.html
Hope that helped!,
Kevin
![Kevin Faust](https://uploads.teamtreehouse.com/production/profile-photos/4112242/micro_python-programming-language.jpg)
Kevin Faust
15,353 PointsNope a toast is different. It's just a temporary message that shows on your screen which goes away after a few seconds. Toasts also have no buttons or anything unlike pop up boxes.
Does that answer your question?
![Mohammad Rahman](https://secure.gravatar.com/avatar/b7ad0bec164e5b11bec1786c546dcda4?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Mohammad Rahman
1,168 PointsSo what is the popup for android? How can I do that?
Thanks
Mohammad Rahman
1,168 PointsMohammad Rahman
1,168 Pointsthanks :)
Kevin Faust
15,353 PointsKevin Faust
15,353 Points