Return to Video

Layout Interstitial Ad

  • 0:00 - 0:02
    So we're going to create two buttons.
  • 0:02 - 0:04
    One with the text load interstitial, and
  • 0:04 - 0:07
    one with the text
    interstitial not ready.
  • 0:07 - 0:10
    Let's first look at the layout
    file where these are defined.
  • 0:10 - 0:13
    So this is going to be in
    the interstitial activity.
  • 0:13 - 0:17
    So we open the activity_interstitial
    layout file here.
  • 0:17 - 0:21
    Here you can see a linear
    layout that has two buttons.
  • 0:21 - 0:24
    The first button is our load button.
  • 0:24 - 0:27
    It has the text Load Interstitial.
  • 0:27 - 0:31
    And when we click on the button the
    loadInterstitial method will be called.
  • 0:31 - 0:35
    The second button is the one
    showing Interstitial Not Ready.
  • 0:35 - 0:40
    And when this button is called, the
    showInterstitial method will be called.
  • 0:40 - 0:43
    And as you can see, I haven't
    really hard coded the text here.
  • 0:43 - 0:46
    These are actually string
    resources that we'll define in
  • 0:46 - 0:47
    our string resource file.
  • 0:48 - 0:51
    So if we look at the definition
    of these constants,
  • 0:51 - 0:53
    we go into our Strings resource file.
  • 0:53 - 0:57
    The interstitial_load constant
    is set to Load Interstitial.
  • 0:57 - 1:01
    The interstitial_not_ready constant
    is set to Interstitial Not Ready.
  • 1:01 - 1:06
    I've also defined a constant called
    interstitial_loading that I set to
  • 1:06 - 1:07
    Loading Interstitial.
  • 1:07 - 1:09
    We'll use that later in our code.
  • 1:09 - 1:14
    Here you can also see that we have
    defined the interstitial_ad_unit_id.
  • 1:14 - 1:18
    This will be the ad unit id that
    we use for our interstitial ad.
  • 1:19 - 1:23
    And as you can see,
    I've hard coded it to this string here,
  • 1:23 - 1:28
    which is the string you can use
    to display test interstitial ads.
  • 1:28 - 1:34
    Similar to this constant up here which
    is the test ad unit id for banner ads.
  • 1:34 - 1:35
    All right, so
  • 1:35 - 1:39
    now when we have our layout file in
    order, lets look at the actual code.
  • 1:39 - 1:42
    So we go into the interstitial
    activity java file.
  • 1:44 - 1:47
    So first of all you can see that
    we've added a member, mShowButton.
  • 1:48 - 1:51
    And in onCreate we call
    our parent's onCreate.
  • 1:51 - 1:54
    Then, we set the content
    view to the layout file
  • 1:54 - 1:58
    of the interstitial activity,
    the one we just looked at.
  • 1:58 - 1:59
    We find the button using,
  • 1:59 - 2:04
    findViewById, providing the showButton
    in the layout file as an argument.
  • 2:04 - 2:06
    And then we disable this button.
  • 2:07 - 2:10
    When the Load Interstitial
    button is clicked, we,
  • 2:10 - 2:13
    again, disable the show button.
  • 2:13 - 2:17
    And then we change its text
    to Loading Interstitial.
  • 2:17 - 2:20
    And, as you can see, this text is also
    something we've defined in our resource
  • 2:20 - 2:24
    file, the interstitial_loading
    resource we just looked at.
  • 2:24 - 2:28
    So we get this string resource
    using getResources and getString.
  • 2:28 - 2:32
    And for now the show interstitial
    callback will be empty.
  • 2:32 - 2:36
    We will add code to this callback later,
    but as you can see, this callback
  • 2:36 - 2:40
    can't even be called right now because
    this button is always disabled.
Cím:
Layout Interstitial Ad
Leírás:

more » « less
Video Language:
English
Team:
Udacity
Projekt:
ud876-3 - Google Play Services - AdMob
Duration:
02:41

English subtitles

Felülvizsgálatok Compare revisions