我正在尝试将InterstitialAd集成到我的应用程序的一个片段中。我正在关注它的官方网站,但如果我输入如下代码,它给我的错误如构造函数InterstitialAd(AuthorListFragment)是未定义的
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);
}
});
}
我在这里缺少什么?
感谢您的帮助:)
答案 0 :(得分: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);
}