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 trialChaitanya chowdary
2,045 PointsThank you.
3 Answers
Eric De Wildt
Courses Plus Student 13,077 PointsThis is what you want, I found this earlier today on stack overflow.
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.cust_toast_layout1(ViewGroup) findViewById(R.id.relativeLayout1));
Toast toast = new Toast(this);
toast.setView(view);
toast.show();
You just need to customize the layout file.
Boris Vukobrat
4,248 PointsAny View object can be shown as toast.
Make .xml layout file with any elements you want. In code, create view by inflating layout, as Eric posted.
You are using inflate(int, ViewGroup)
method, where first parameter is reference to a layout file, and the second is reference to a viewGroup that you will be showing in toast. So your viewGroup must have @+id
tag
Mohammad Abdirashid
8,211 PointsThanks Eric and Boris,
Eric De Wildt
Courses Plus Student 13,077 PointsYou're welcome!
Mohammad Abdirashid
8,211 PointsMohammad Abdirashid
8,211 PointsIt is a good practice and makes you a better programming to always know how to read and understand the API classes. If you see this link: http://developer.android.com/reference/android/widget/Toast.html#Toast(android.content.Context)
I didn't see any method in the Toast class that let's you add ImageView. The only method that is close you can try is setView(View view). But I think this represents the Toast View itself. Update us, if you figured it out -)