English subtitles

← 06c s Add TextView for Price

Get Embed Code
13 Languages

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

  1. First we need to modify
    the activity main layout so
  2. that we can add the text views for
  3. If the device preview
    isn't showing already,
  4. you can click on this link here that
    says Preview in order to make it appear.
  5. Now, when we change the XML, we can
    just see it update automatically, here.
  6. In this screen shot we provided for
  7. you, the price was presented in
    a similar way to the quantity.
  8. We have a header, as well as
    a text view, to show the value.
  9. So we can just copy over these
    two text view elements and
  10. then paste it beneath it.
  11. Now we just need to tweak
    the values to fit our scenario.
  12. Instead of quantity,
    it should say price.
  13. And, we should also change
    the ID to be price text view.
  14. You can have two views with the same ID.
  15. But, anyways, in the quiz, we told you
    to change this to be price text view.
  16. So, it would match our code.
  17. There.
    And that makes the error go away.
  18. Okay, looking at the preview, we have
    the price header, and zero beneath it.
  19. We also want to just change
    this just to be zero dollars.
  20. And you can use your own
    currency symbol if you want.
  21. The header is in all caps and
  22. the actual price value has the text
    size of 16 sp and a black text color.
  23. That looks good so far, except I do
    notice there needs to be a little
  24. more vertical space between the price
    header and the quantity value.
  25. I'm just going to
    change all the views so
  26. that they have a margin top,
    value of 16dp.
  27. And then instead of margin bottom here,
    I'm just going to do, margin top,
  28. 16, and that actually fixes it.
  29. Cool.
  30. Now all the views
    are evenly spaced apart.
  31. Once you think the XML
    is in a good state,
  32. then you can just run it on your device.
  33. Cool, and that looks good.
  34. Let's work on the MainActivity file now.
  35. If this Android DDMS window pops up, you
    can just collapse it using this arrow.
  36. In the MainActivity,
    we asked you to copy and
  37. paste the displayPrice
    method that we gave you.
  38. Hopefully, you also modified
    your Android Studio preferences
  39. to automatically import things
    if they were unambiguous.
  40. That would help resolve the problem
    of it not knowing what number format
  41. referred to.
  42. But now with the import statement,
    the app knows that number format is
  43. something that's provided automatically
    by Java to help format numbers.
  44. Then for the last step, we modify
    the submit order method, so that when
  45. the button is clicked, we display
    the quantity and also display the price.