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

Tim Arwine
Tim Arwine
5,406 Points

Fun Facts App -- One Step More: Photos

I'd like to add a photo to accompany each fun fact. I'm sure that would mean having another class for the pics, but I'm not sure what else would be needed. Does anybody know how to do this? Or has anyone else already done this? Thank You!!

2 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Hey Tim, sounds like a great idea to extend the project! I'd highly recommend continuing with Build an Interactive Story App course, which teaches how to add images and other elements to Activities. Images are covered in the first stage, so if you watch that you can probably come back and more easily accomplish this enhancement.

Tim Arwine
Tim Arwine
5,406 Points

Ben, Thank you so much! It sounds so obvious now that you say that. Anyway, I will go jump into that course and let you know if anything is still unclear. Thanks again-

Or Kramer
Or Kramer
3,072 Points

Try to use add class named Fact with the below fields:

private String mFactString;

private int mFactImageID;

the mFactImageID will be set later to - R.drawable.image1 (which is int) and it will be used to set the Image later in the Activity.

here is a reference for how to add Image in XML + Activity: http://stackoverflow.com/questions/5089300/how-can-i-change-the-image-of-an-imageview

here is nice reference example for how the Fact class should be and using arrayList: http://stackoverflow.com/questions/8366202/how-to-declare-arraylist-to-store-integers-and-strings-in-android

*Don't forget to add your image in the res->drawable folder so your IDE will recognize it. Goodluck :)

Tim Arwine
Tim Arwine
5,406 Points

Or, Thank you very much. I am still trying to understand everything in your answer and those tutorials. (Still a beginner. I don't immediately connect all the dots :) I understand adding the class Fact with those two field variables. I also understand putting my photo in the res -> drawable folder, but I'm still foggy on how I'll go about setting the mFactImageID in the activity. I will continue to study this material. In the meantime, would it be possible to provide a bit more detail? Thanks!