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 trialTaylor Bryant
7,395 PointsWhy are we modifying the holder yet returning a view?
Why are we setting the holders fields with our day object properties and then immediately returning the convert view instead?
1 Answer
Taylor Bryant
7,395 PointsThe Video is from the android course going over listviews, The Setting the Data video from Custom list views and adapters section
'''
@Override public View getView(int position, View convertView, ViewGroup viewGroup) { ViewHolder holder;
if(convertView == null){
//brand new view
convertView = LayoutInflater.from(mContext).inflate(R.layout.daily_list_item, null);
holder = new ViewHolder();
holder.iconImageView = (ImageView) convertView.findViewById(R.id.iconImageView);
holder.temperatureLabel = (TextView) convertView.findViewById(R.id.temperatureLabel);
holder.dayLabel = (TextView) convertView.findViewById(R.id.dayNameLabel);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
Day day = mDays[position];
holder.iconImageView.setImageResource(day.getIconId());
holder.temperatureLabel.setText(day.getTemperatureMax() + "");
if (position == 0 ){
holder.dayLabel.setText("Today");
}else{
holder.dayLabel.setText(day.getDayOfTheWeek());
}
return convertView;
}
'''
Philip Gales
15,193 PointsPhilip Gales
15,193 PointsPlease post your code and maybe what course you are on and the video.