public View getView(int position, View convertView, ViewGroup parent) {

    ViewHolder viewHolder;

    // Use ViewHolder pattern to only inflate once
    if (convertView == null) {
      convertView = inflater.inflate(R.layout.list_of_list_line_item, parent, false);

      viewHolder = new ViewHolder();
      viewHolder.countView = (TextView) convertView.findViewById(R.id.count);
      viewHolder.nameView = (TextView) convertView.findViewById(R.id.name);
      convertView.setTag(viewHolder);
    } else {
      viewHolder = (ViewHolder) convertView.getTag();
    }

    if (position % 2 == 0) convertView.setBackgroundColor(Color.BLACK);
    else convertView.setBackgroundColor(Color.DKGRAY);

    Pair<String, Integer> response = items.get(position);
    viewHolder.nameView.setText(response.first);
    if (response.second != null && response.second > 0)
      viewHolder.countView.setText("" + response.second);
    else viewHolder.countView.setText("");

    return convertView;
  }
  @Override
  public View getView(int i, View convertView, ViewGroup viewGroup) {
    View view = convertView;
    ViewHolder holder;
    if (view == null) {
      view = inflater.inflate(layoutId, null);
      holder = new ViewHolder();
      holder.nameView = ButterKnife.findById(view, nameTextViewId);
      holder.albumView = ButterKnife.findById(view, albumTextViewId);
      holder.image = ButterKnife.findById(view, imageViewId);
      view.setTag(holder);
    } else {
      holder = (ViewHolder) view.getTag();
    }

    Track track = data.get(i);
    if (track == null || track.getName() == null || track.getAlbum() == null)
      throw new IllegalArgumentException("Track in adapter was incorrect. Track => " + track);
    String imageUrl = track.getImageUrl();
    if (imageUrl != null && imageUrl.length() > 0)
      Picasso.with(context).load(imageUrl).into(holder.image);
    else Picasso.with(context).load(R.drawable.no_image_available).into(holder.image);

    holder.nameView.setText(track.getName());
    holder.albumView.setText(track.getAlbum());
    return view;
  }
Пример #3
0
    /** {@inheritDoc} */
    @Override
    public View newView(Context context, final Cursor cursor, ViewGroup parent) {
      final View view =
          LayoutInflater.from(context).inflate(R.layout.grid_item_artist, parent, false);

      // Setup View holder pattern
      ViewHolder viewHolder = new ViewHolder();
      viewHolder.nameView = (TextView) view.findViewById(R.id.name);
      viewHolder.genresView = (TextView) view.findViewById(R.id.genres);
      viewHolder.artView = (ImageView) view.findViewById(R.id.art);

      view.setTag(viewHolder);
      return view;
    }
Пример #4
0
  private ViewHolder getViewHolder(final View workingView) {
    final Object tag = workingView.getTag();
    ViewHolder viewHolder = null;

    if (null == tag || !(tag instanceof ViewHolder)) {
      viewHolder = new ViewHolder();

      viewHolder.nameView = (TextView) workingView.findViewById(R.id.name);
      viewHolder.dateView = (TextView) workingView.findViewById(R.id.date);
      viewHolder.sizeView = (TextView) workingView.findViewById(R.id.size);
      viewHolder.imageView = (ImageView) workingView.findViewById(R.id.image);

      workingView.setTag(viewHolder);

    } else {
      viewHolder = (ViewHolder) tag;
    }

    return viewHolder;
  }
Пример #5
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;
    if (convertView == null) {
      convertView =
          View.inflate(this.getContext(), R.layout.main_trainingschedule_overview_exercise, null);
      viewHolder = new ViewHolder();
      viewHolder.poseView =
          (ImageView) convertView.findViewById(R.id.main_trainingschedule_workout_type);
      viewHolder.nameView =
          (TextView) convertView.findViewById(R.id.main_trainingschedule_workout_name);

      convertView.setTag(viewHolder);
    } else {
      viewHolder = (ViewHolder) convertView.getTag();
    }

    Exercise exercise = this.exercises.get(position);
    viewHolder.poseView.setImageResource(this.exerciseIcons[exercise.getWorkoutType() - 1]);
    viewHolder.nameView.setText(exercise.getName());

    return convertView;
  }
Пример #6
0
    public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder;
      View row = convertView;
      if (row == null) {

        row = mInflater.inflate(R.layout.activity_main, parent, false);
        holder = new ViewHolder();
        holder.imageView = (ImageView) row.findViewById(R.id.flag);
        holder.nameView = (TextView) row.findViewById(R.id.name);
        holder.capitalView = (TextView) row.findViewById(R.id.capital);
        row.setTag(holder);
      } else {

        holder = (ViewHolder) row.getTag();
      }

      State state = getModel(position);

      holder.imageView.setImageResource((state.getFlagResource()));
      holder.nameView.setText(state.getName());
      holder.capitalView.setText(state.getCapital());

      return row;
    }