2016-07-06 116 views
1

我正在嘗試將InterstitialAd集成到我的應用程序片段之一中。我下面爲它的官方網站,但如果象下面這樣它給我的錯誤一樣的構造在InterstitialAd(AuthorListFragment)我輸入的代碼是未定義構造函數InterstitialAd

The constructor InterstitialAd(MyListFragment) is undefined 

我的完整代碼就像下面。

public View onCreateView(LayoutInflater inflater, ViewGroup group,Bundle savedState){ 
    super.onCreateView(inflater,group,savedState); 

    return inflater.inflate(R.layout.fragment_home,null); 


    mInterstitialAd = new InterstitialAd(this); 
    mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712"); 
    final AdRequest adRequest = new AdRequest.Builder() 
    .addTestDevice("7C77ADF1D83FA8B87C0481D6748FA4DB") 
    .build(); 
    mInterstitialAd.loadAd(adRequest); 

    mInterstitialAd.setAdListener(new AdListener() { 
     @Override 
     public void onAdClosed() { 
      AdRequest adRequest = new AdRequest.Builder() 
      .addTestDevice("7C77ADF1D83FA8B87C0481D6748FA4DB") 
      .build(); 
      mInterstitialAd.loadAd(adRequest); 
     } 
    }); 
} 

我在想什麼?

感謝您的幫助:)

回答

3
public View onCreateView(LayoutInflater inflater, ViewGroup group,Bundle savedState){ 
    super.onCreateView(inflater,group,savedState); 

    //return inflater.inflate(R.layout.fragment_home,null); 
    // take this to end 

    mInterstitialAd = new InterstitialAd(getActivity()); 
    mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712"); 
    final AdRequest adRequest = new AdRequest.Builder() 
    .addTestDevice("7C77ADF1D83FA8B87C0481D6748FA4DB") 
    .build(); 
    mInterstitialAd.loadAd(adRequest); 

    mInterstitialAd.setAdListener(new AdListener() { 
     @Override 
     public void onAdClosed() { 
      AdRequest adRequest = new AdRequest.Builder() 
      .addTestDevice("7C77ADF1D83FA8B87C0481D6748FA4DB") 
      .build(); 
      mInterstitialAd.loadAd(adRequest); 
     } 
    }); 
    return inflater.inflate(R.layout.fragment_home,null); 

} 
+0

哇!謝謝兄弟:)其工作像魅力:) –

+0

請打勾並投票,而不是說謝謝。 –

+0

我打算接受你的回答:) –