コード例 #1
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    MovieData movieData = getItem(position);

    ViewHolder holder;

    if (convertView != null) {
      holder = (ViewHolder) convertView.getTag();
    } else {
      convertView =
          LayoutInflater.from(getContext()).inflate(R.layout.movie_grid_item, parent, false);
      holder = new ViewHolder(convertView);
      convertView.setTag(holder);
    }

    Picasso.with(getContext())
        .load(movieData.getPosterURL())
        .placeholder(ContextCompat.getDrawable(getContext(), R.drawable.poster_placeholder))
        .error(ContextCompat.getDrawable(getContext(), R.drawable.poster_placeholder))
        .into(holder.moviePoster);

    holder.popularityText.setText(String.format("%.0f", movieData.popularity));
    holder.ratingText.setText(String.format("%.1f / 10", movieData.voteAverage));

    return convertView;
  }