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 trialSana Khateeb
3,979 PointstemperatureLabel and circleImageView not showing?
I've been stuck on this error for a while now - I have gone through the videos and I have no compile or exceptions being thrown, but for some reason when I press the 7-day button it only shows the icon and the dayName, not the other two. Someone else asked this question before and the solution was to rearrange the XML, however that did not help my case. I also looked for the answer on Stackoverflow and couldn't find anything relevant.
Link to my most recent code: https://github.com/SanaKhateeb/WeatherApp
Any help will be appreciated, I'm pretty stuck.
3 Answers
Sana Khateeb
3,979 PointsFixed this thanks Robert Dandy -- needed to keep reloading the circleImageView in getView()
Link to the discussion question that fixed my problem.
Boban Talevski
24,793 PointsSuffering from the same issue, but since I was finding it a little bit weird to have to reload static images in the getView() method in the adapter (it does work though), I compared my code with Ben's and in the layout daily_list_item.xml file for the circleImageView instead of
app:srcCompat="@drawable/bg_temperature"
I put
android:src="@drawable/bg_temperature"
which seems to have solved the problem for me and now it displays the temperature correctly.
It probably has something to do with SDK versions and the fact that for a while AS does automatically extend the Activity class from AppCompatActivity (which most of us working on the course for the past year or so had initially), and then we change that to ListActivity for the purpose of this course, and somehow something breaks because all other things assume we had extended from AppCompatActivity. Which is probably why the xml automatically sourced the image using app:srcCompat instead of (the probably older) android:src attribute.
The difference between app:srcCompat and android:src seems to be that the former should be used for vector graphics and the latter is used for the "usual" png graphics as we have here. So I assume this is a valid solution for fixing this issue because it doesn't make much sense to add source drawables for views that remain static in a method that gets called for every listview item and should be used to populates the views with dynamic data.
I'm having two such circles in my list item because I'm showing both the low and the high temperature for the day, but imagine having even more small icons as some styling in every list item and having to simply add the same png drawable repeatedly on each getView method call dynamically. I don't think the code will be pretty, and there's also probably some performance hit along with it.
DHANANJAY TRIVEDI
Courses Plus Student 403 Points@Override public View getView(int position, View convertView, ViewGroup viewGroup) { ViewHolder holder; //REUSING THE VIEW IN ADAPTER
if (convertView == null){
convertView = LayoutInflater.from(mContext).inflate(R.layout.daily_list_item, null);
holder = new ViewHolder();
holder.imgTempCircle = (ImageView) convertView.findViewById(R.id.circleImageView);
holder.iconImageView = (ImageView) convertView.findViewById(R.id.iconImageView);
holder.temperatureLabel = (TextView) convertView.findViewById(R.id.tempLabel);
holder.dayLabel = (TextView) convertView.findViewById(R.id.dayNameLabel);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
Day day = mDays[position];
holder.imgTempCircle.setImageResource(R.drawable.bg_temperature);
holder.iconImageView.setImageResource(day.getIconId());
holder.temperatureLabel.setText(day.getTemperatureMax() + "");
holder.dayLabel.setText(day.getDayOfTheWeek());
return convertView;
}
private static class ViewHolder {
ImageView imgTempCircle;
ImageView iconImageView;
TextView temperatureLabel;
TextView dayLabel;
}