@Override public View getView(int position, View convertView, ViewGroup parent) { // Get the data item for this position RedditChild child = getItem(position); // Check if an existing view is being reused, otherwise inflate the view if (convertView == null) { convertView = mInflater.inflate(R.layout.list_item_reddit, null, false); viewHolder = new ViewHolder(); viewHolder.thumbnailView = (ImageView) convertView.findViewById(R.id.list_item_thumbnail); viewHolder.titleView = (TextView) convertView.findViewById(R.id.list_item_title_textview); viewHolder.authorView = (TextView) convertView.findViewById(R.id.list_item_author_textview); Typeface typeFace = Typeface.createFromAsset(mContext.getAssets(), "fonts/bebasneue.ttf"); viewHolder.authorView.setTypeface(typeFace); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } // Populate the data into the template view using the data object viewHolder.titleView.setText(child.getData().getTitle()); viewHolder.authorView.setText("@" + child.getData().getAuthor().toUpperCase()); if (!child.getData().getThumbnail().isEmpty()) { Picasso.with(mContext) .load(child.getData().getThumbnail()) .placeholder(R.mipmap.ic_launcher) .into(viewHolder.thumbnailView); } else { viewHolder.thumbnailView.setImageResource(R.mipmap.ic_launcher); } // Return the completed view to render on screen return convertView; }
private ViewHolder createViewHolder(LayoutInflater inflater, LinearLayout parent) { ViewHolder holder = new ViewHolder(); holder.rowView = inflater.inflate(R.layout.row_course_dashboard_list, parent, false); holder.typeView = (IconView) holder.rowView.findViewById(R.id.row_type); holder.titleView = (TextView) holder.rowView.findViewById(R.id.row_title); holder.subtitleView = (TextView) holder.rowView.findViewById(R.id.row_subtitle); parent.addView(holder.rowView); return holder; }
public void onBindViewHolder(ViewHolder holder, final int position) { if (seasons.get(position).number() == 0) holder.titleView().setText("Specials"); else holder.titleView().setText("Season " + seasons.get(position).number()); if (seasons.get(position).episodeCount() != 1) holder.episodesView().setText(seasons.get(position).episodeCount() + " episodes"); else holder.episodesView().setText(seasons.get(position).episodeCount() + " episode"); Glide.with(mContext) .load(seasons.get(position).images().poster().get(Images.ImageSize.FULL)) .placeholder(R.drawable.show_item_placeholder) .centerCrop() .into(holder.thumbnailView()); holder .root() .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { mListener.onSeasonClick(getItem(position)); } }); }
private ViewHolder getViewHolder(final View workingView) { // The viewHolder allows us to avoid re-looking up view references // Since views are recycled, these references will never change final Object tag = workingView.getTag(); ViewHolder viewHolder = null; if (null == tag || !(tag instanceof ViewHolder)) { viewHolder = new ViewHolder(); viewHolder.titleView = (TextView) workingView.findViewById(R.id.file_entry_title); viewHolder.subTitleView = (TextView) workingView.findViewById(R.id.file_entry_subtitle); viewHolder.imageView = (ImageView) workingView.findViewById(R.id.file_entry_icon); workingView.setTag(viewHolder); } else { viewHolder = (ViewHolder) tag; } return viewHolder; }
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; int type = getItemViewType(position); if (convertView == null) { holder = new ViewHolder(); switch (type) { case TYPE_ITEM: convertView = mInflater.inflate(R.layout.fragment_subject_item, null); holder.titleView = (TextView) convertView.findViewById(R.id.text_subject_item_title); holder.dateView = (TextView) convertView.findViewById(R.id.text_subject_item_time); holder.roomView = (TextView) convertView.findViewById(R.id.text_subject_item_room); if (position % 2 == 0) { convertView.setBackgroundColor( context.getResources().getColor(R.color.abs__background_holo_dark)); } else { convertView.setBackgroundColor( context.getResources().getColor(R.color.abs__background_holo_light)); } break; case TYPE_SEPARATOR: convertView = mInflater.inflate(R.layout.fragment_subject_separator, null); holder.separatorView = (TextView) convertView.findViewById(R.id.text_subject_separator); break; } convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } if (type == TYPE_ITEM) { final Events item = mData.get(position); if (item != null) { if (selection == item.getId()) { convertView.setBackgroundResource(R.drawable.abs__list_activated_holo); int padding = context.getResources().getDimensionPixelSize(R.dimen.default_list_padding); convertView.setPadding(padding, padding, padding, padding); } else { convertView.setBackgroundResource(android.R.color.transparent); } try { holder.titleView.setText(item.getSubjects().getTitle()); } catch (Exception e) { Log.e(TAG, item.getSubjectId() + " " + item.getSubjects()); HashMap<String, String> extraData = new HashMap<String, String>(); extraData.put("subjectsid", String.valueOf(item.getSubjectId())); extraData.put("subjects", String.valueOf(item.getSubjects())); BugSenseHandler.sendExceptionMap(extraData, e); } holder.roomView.setText(item.getRoom()); holder.dateView.setText(df.format(item.getStart()) + " - " + df.format(item.getEnd())); } } else { try { Calendar nextSeperatorDate = Calendar.getInstance(); nextSeperatorDate.setTime(fullDateFormat.parse(getSeperatorItem(position))); long dateDiff = daysDiff(Calendar.getInstance(), nextSeperatorDate); if (dateDiff == 0) { holder.separatorView.setText(context.getString(R.string.text_today)); } else if (dateDiff == 1) { holder.separatorView.setText(context.getString(R.string.text_tomorrow)); } else if (dateDiff == -1) { holder.separatorView.setText(context.getString(R.string.text_yesterday)); } else if (dateDiff == -2) { holder.separatorView.setText(context.getString(R.string.text_twoago)); } else { holder.separatorView.setText(getSeperatorItem(position)); } } catch (Exception e) { holder.separatorView.setText(getSeperatorItem(position)); BugSenseHandler.sendException(e); } } return convertView; }