示例#1
0
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
      Result result = searchResults.getResults().get(position);
      ImageView image = (ImageView) holder.itemView.findViewById(R.id.card_image);
      TextView title = (TextView) holder.itemView.findViewById(R.id.card_title);
      TextView text = (TextView) holder.itemView.findViewById(R.id.card_text);
      TextView textSecondary = (TextView) holder.itemView.findViewById(R.id.card_text_secondary);

      if (result.getThumb() != null && !result.getThumb().isEmpty())
        Picasso.with(mContext)
            .load(result.getThumb())
            .placeholder(R.drawable.bg_side_nav_bar)
            .error(R.drawable.bg_side_nav_bar)
            .into(image);

      if (result.getType().equals("master")) {
        String titleOnly = result.getTitle().split(" - ")[1];
        String artistOnly = result.getTitle().split(" - ")[0];
        title.setText(titleOnly);
        text.setText(artistOnly);
        textSecondary.setText(result.getType());
      } else if (result.getType().equals("release")) {
        String titleOnly = result.getTitle().split(" - ")[1];
        String artistOnly = result.getTitle().split(" - ")[0];
        title.setText(titleOnly);
        text.setText(TextUtils.join(", ", result.getFormat()));
        textSecondary.setText(result.getLabel().get(0) + " - " + result.getCountry());
      } else if (result.getType().equals("artist")) {
        title.setText(result.getTitle());
        text.setText(result.getType());
        textSecondary.setText("");
      } else if (result.getType().equals("label")) {
        title.setText(result.getTitle());
        text.setText(result.getType());
        textSecondary.setText("");
      }
    }