Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← 9 s Add code to list all dinners

Get Embed Code
4 Languages

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

  1. So now I'm going to look at the code
    that I added to implement the scrolling
  2. list of all the dinners.
  3. So the first thing I'm going to do is in
    the package,
  4. I'm going to add a new Java class
    called ShowAllDinnersActivity.
  5. This class extends ListActivity.
  6. It knows how to get a list
    of all the dinners.
  7. It uses an adapter to display
    all the dinners in the list, and
  8. it defines the onListItemClick, so
    that when an item on the list is
  9. clicked we send an intent to start
    the OrderDinnerActivity, and
  10. passing in the selectedDinner.
  11. Now over, in Main Activity, we add the
    showDinnerList method, which is going to
  12. be invoked whenever somebody clicks on
    the show me all the dinners button.
  13. And all this method does,
  14. is it sends an intent to start
    the ShowAllDinnersActivity.
  15. So that's it for the code, but
    now we need to do the layouts.
  16. The first thing I'm going to do is
    add the button to the main screen,
  17. to list all the dinners.
  18. And there it is, show all the dinners.
  19. But I'm not done with the layout yet.
  20. I need to add
    the listalldinners.xml file,
  21. which is a list of all the dinners.
  22. So we need to add
    the showdinnerinrow.xml layout file,
  23. which is a layout for
    each dinner entry in the list.
  24. All right, that should do it.
  25. So, I'm going to redeploy my app and
  26. hopefully we'll see
    the changes in the UI.
  27. So of course, one more thing you
    need to do in the code is to update
  28. the AndroidManifest.xml to include your
    new class, ShowAllDinnersActivity.
  29. If you don't do this, it It won't work.
  30. So that's all there is to it.
  31. Now I'm going to run my app again,
    and let's see if it works.
  32. So, I press my Show All the Dinners,
    and let's see.
  33. Oh, and there's my list of dinners.
  34. Cool.