title: Using AdMob from within a Fragment?
body: <p>I've begun working on a new application and I decided to start this one off using <code>Fragment</code>s via the v13 Support package so I can build one app that does both phone &amp; tablet designs.</p>
  
  <p>I have my AdMob ads working from within a Fragment if I do the creation of them from within the XML file, however, if I try to create them via code I'm running into issues.</p>
  
  <pre><code>public class Fragment_Admob extends Fragment implements AdListener 
  {
  
      private static final String LOG_TAG = "Fragment_Admob";
  
      private AdView adView;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
      {
  
          // Inflate the layout for this fragment
          return inflater.inflate(R.layout.admob_view, container, false);
  
          // Create an ad.
          adView = new AdView(this, AdSize.BANNER, "My_AdMob_Code");
  
          ...
      }
  
      ...
  }
  </code></pre>
  
  <p>Eclipse tells me:</p>
  
  <blockquote>
    <p>The constructor AdView(Fragment_Admob, AdSize, String) is undefined</p>
  </blockquote>
  
  <p>so I was like ok that makes sense as AdView expects an Activity and not a Fragment.  So I tried making the class extend FragmentActivity instead of Fragment and that resolved that particular issue.  However now I have fragment expansion issues at runtime which I've worked through before but I am unable to resolve here because I really don't think I'm supposed to use FragmentActivity in a non-activity set of code.</p>