Android Toasts (e.g. small notifications), how to use in Fragments

The syntax is very simple. The example below is invoked from inside a Fragment, so the first parameter (Context) is the activity that holds the fragment:

Toast.makeText(getActivity(),R.string.asset_added_fav,Toast.LENGTH_SHORT).show();

The second parameter is the message, the third is the duration, Toast.makeText returns an instance of Toast, that we “.show()” immediately.


Posted

in

by

Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from try {} except

Subscribe now to keep reading and get access to the full archive.

Continue reading