English subtitles

← Layout Interstitial Ad

Get Embed Code
5 Languages

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

  1. So we're going to create two buttons.
  2. One with the text load interstitial, and
  3. one with the text
    interstitial not ready.
  4. Let's first look at the layout
    file where these are defined.
  5. So this is going to be in
    the interstitial activity.
  6. So we open the activity_interstitial
    layout file here.
  7. Here you can see a linear
    layout that has two buttons.
  8. The first button is our load button.
  9. It has the text Load Interstitial.
  10. And when we click on the button the
    loadInterstitial method will be called.
  11. The second button is the one
    showing Interstitial Not Ready.
  12. And when this button is called, the
    showInterstitial method will be called.
  13. And as you can see, I haven't
    really hard coded the text here.
  14. These are actually string
    resources that we'll define in
  15. our string resource file.
  16. So if we look at the definition
    of these constants,
  17. we go into our Strings resource file.
  18. The interstitial_load constant
    is set to Load Interstitial.
  19. The interstitial_not_ready constant
    is set to Interstitial Not Ready.
  20. I've also defined a constant called
    interstitial_loading that I set to
  21. Loading Interstitial.
  22. We'll use that later in our code.
  23. Here you can also see that we have
    defined the interstitial_ad_unit_id.
  24. This will be the ad unit id that
    we use for our interstitial ad.
  25. And as you can see,
    I've hard coded it to this string here,
  26. which is the string you can use
    to display test interstitial ads.
  27. Similar to this constant up here which
    is the test ad unit id for banner ads.
  28. All right, so
  29. now when we have our layout file in
    order, lets look at the actual code.
  30. So we go into the interstitial
    activity java file.
  31. So first of all you can see that
    we've added a member, mShowButton.
  32. And in onCreate we call
    our parent's onCreate.
  33. Then, we set the content
    view to the layout file
  34. of the interstitial activity,
    the one we just looked at.
  35. We find the button using,
  36. findViewById, providing the showButton
    in the layout file as an argument.
  37. And then we disable this button.
  38. When the Load Interstitial
    button is clicked, we,
  39. again, disable the show button.
  40. And then we change its text
    to Loading Interstitial.
  41. And, as you can see, this text is also
    something we've defined in our resource
  42. file, the interstitial_loading
    resource we just looked at.
  43. So we get this string resource
    using getResources and getString.
  44. And for now the show interstitial
    callback will be empty.
  45. We will add code to this callback later,
    but as you can see, this callback
  46. can't even be called right now because
    this button is always disabled.