English subtitles

← Using RecyclerView Part 2 (quiz)

Get Embed Code
4 Languages

Showing Revision 3 created 05/25/2016 by Udacity Robot.

  1. The recycler view is set up so
  2. that a single adapter can
    drive multiple recycler views.
  3. To add back end support for
    click handling and
  4. empty views, we're going to give the
    recycler view adapter knowledge of our
  5. particular recycler view, which does
    kind of break the standard model.
  6. But it's alright,
    because we're not going to
  7. be driving multiple recycler
    views to our single adapter.
  8. So we're going to add
    back click handling and
  9. empty view into forecast fragment.
  10. In forecast adapter, we're going to
    create a forecast adapter on click
  11. handler that returns a date long,
    and a ForecastAdapter ViewHolder.
  12. And then we're going to add
    a ForecastAdapteronClickHandler
  13. member variable.
  14. We're going to update the
    ForecastAdapter constructor to have it
  15. take the ForecastAdapteronClickHandler
    and empty view.
  16. Then we'll have
    ForecastAdapterviewHolder implement
  17. a view.OnClickListener.
  18. And when you construct a viewHolder,
  19. set the viewHolder to be
    the OnClickListener for the view.
  20. So, does that make sense?
  21. You basically pass in the view to
    the ViewHolder when you construct it.
  22. You have the ViewHolder
    implement OnClickListener and
  23. then, you actually set that viewHolder
    to be the OnClickListener for
  24. the view at that time of construction.
  25. Then, you call the ForecastAdapter
    OnClickListener from your
  26. individual ViewHolder OnClickListener.
  27. If you have any questions,
  28. I'm sure we'll have some
    great instructor notes here.
  29. Set the visibility of the empty view
    In SwapCursor based upon the item count.
  30. So this is pretty simple,
  31. we're going to put back in empty
    view handling which is awesome.
  32. And then in the ForecastFragment,
  33. we're going to add back in empty
    view and onClick handling.
  34. When I say in ForecastFragment, add
    back in empty view and onClick handling,
  35. what I mean is we commented a whole
    bunch of code out in ForecastFragment.
  36. We're going to un-comment that, and then
    we're going to connect it up to these
  37. new mechanisms we've built to handle
    empty view and onClick handling.