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 trialremkl
18,150 PointsHooking up data to TextView - weather app
When updating the display method, I am not sure which object I should be calling to invoke the getTitle() method in the Movie class. eg: mTitleLabel.setText( ? .getTitle());
Any help or clarification is appreciated.
Thanks
3 Answers
james white
78,399 PointsChallenge Link:
Challenge Task 1 of 2
Time to hook up some movie data! In the updateDisplay() method, set the title TextView using the appropriate method from the Movie class.
Challenge Task 2 of 2
Now let's set the image using the Movie method that gets the appropriate ID.
This seems like an easy challenge but it was definitely NOT!
For the first part of the challenge this is all you need:
public void updateDisplay(Movie movie) {
// Add your code here!
mTitleLabel.setText(movie.getTitle());
}
The second part of the challenge is the tricky part...
This is the video that "sort of" gives you a hint as to what is needed: http://teamtreehouse.com/library/build-a-weather-app/hooking-up-the-model-to-the-view/setting-the-weather-icon
But you should dig around in the zip project files for "MainActivity.java" and search for "updateDisplay()".
If you do you'll find this code:
private void updateDisplay() {
mTemperatureLabel.setText(mCurrentWeather.getTemperature() + "");
mTimeLabel.setText("At " + mCurrentWeather.getFormattedTime() + " it will be");
mHumidityValue.setText(mCurrentWeather.getHumidity() + "");
mPrecipValue.setText(mCurrentWeather.getPrecipChance() + "%");
mSummaryLabel.setText(mCurrentWeather.getSummary());
Drawable drawable = getResources().getDrawable(mCurrentWeather.getIconId());
mIconImageView.setImageDrawable(drawable);
}
The important part is the last two lines that define and use 'drawable'.
To "translate" this code into what the challenge wants/needs
you have to know:
1.) That mIconImageView is an imageview name and the code challenge uses a corresponding ImageView name of "mMovieImage"
2.) That .getIconId gets a number (an "int" number) corresponding to an image/picture, so the corresponding getter in the Movie class is 'movie.getImageId()'
3.) That setImageDrawable DOES NOT correspond to the movie class setter 'setImageId(int id)' (Ha! Ha! Fooled you! )
So (without further ado) the code that should pass:
public void updateDisplay(Movie movie) {
// Add your code here!
mTitleLabel.setText(movie.getTitle());
Drawable drawable = getResources().getDrawable(movie.getImageId());
mMovieImage.setImageDrawable(drawable);
}
Oh yeah, you say:
"I could have pounded out that code right off the top of my head"
If so you are better coder than I who had to spend over an hour researching this one.. (that's the "unamused" emoji/empticon)
remkl
18,150 PointsThanks mate, I understand it now and got it working, that was more than helpful!
Your help is very much appreciated :).
Keep up the good work.
wesley franks
6,198 PointsThank you, this definitely helped me as I was stuck, because there wasn't exactly an explained concept there. I need to learn, but sometimes I get frustrated, because we can be left hanging not having a clue. Had they explained the concept that way to at least define the concepts a bit more. Instead of just typing code away I would have been able to figure it.
I understand their concept of needing to let the user(me), learn to research and figure out the problem, because treehouse can't be there in the real world applications, but places like Stack Exchange and other places "sorta" can depending not the code being worked on.
Any ways thanks bro.
jenyufu
3,311 PointsYeah honestly, i hate how they didn't explain the concept of why we were doing what we do and how to replicate it in the last few lessons. He basically just told us to do this, do that with no explanations
MUZ140842 Canaan Zimba
1,829 Pointshie. where do I find the zip for my project files
jenyufu
3,311 Pointsjenyufu
3,311 PointsThank you so much!