Beispiel #1
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_recycler_with_header, container, false);

    if (mResults.getResults().size() == 0)
      Snackbar.make(container, "No results found", Snackbar.LENGTH_LONG)
          .setAction("Action", null)
          .show();

    RecyclerViewHeader header = (RecyclerViewHeader) rootView.findViewById(R.id.header);
    TextView heading1 = (TextView) rootView.findViewById(R.id.heading1);
    TextView heading2 = (TextView) rootView.findViewById(R.id.heading2);
    heading1.setText(mHeading1);
    heading2.setText(mHeading2);
    RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.my_recycler_view);
    ResultAdapter adapter = new ResultAdapter(getActivity().getApplicationContext(), mResults);
    recyclerView.setAdapter(adapter);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    header.attachTo(recyclerView, true);
    return rootView;
  }
Beispiel #2
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("");
      }
    }
Beispiel #3
0
 @Override
 public int getItemCount() {
   return searchResults.getResults().size();
 }