int[] images = { R.drawable.r1,R.drawable.r2,R.drawable.r3,R.drawable.r4,R.drawable.r5,R.drawable.r6,R.drawable.r7,R.drawable.r8,R.drawable.r9,R.drawable.r10 /// so on}; public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.main); // for interstitial interstitial = new InterstitialAd ( this ); interstitial.setAdUnitID (my ad ID); AdRequest.Builder adRequestBuilder=new AdRequest.Builder (); interstitial.setAdListener ( new AdListener (){ } }); interstitial.loadAd ( adRequestBuilder.Build ()); hImageVIEwPic = (ImageVIEw)findVIEwByID(R.ID.IDImageVIEwPic); ibutton = (button) findVIEwByID(R.ID.bNext); gbutton = (button) findVIEwByID(R.ID.bPrev); //Just set one Click Listener for the image ibutton.setonClickListener(ibuttonChangeImageListener); gbutton.setonClickListener(gbuttonChangeImageListener); } VIEw.OnClickListener ibuttonChangeImageListener = new OnClickListener() { public voID onClick(VIEw v) { //Increase Counter to move to next Image currentimage++; currentimage = currentimage % images.length; hImageVIEwPic.setimageResource(images[currentimage]); / / here to show interstitial if (interstitial. isLoaded ()){ interstitial.show (); } } }; VIEw.OnClickListener gbuttonChangeImageListener = new OnClickListener() { public voID onClick(VIEw v) { //Increase Counter to move to next Image currentimage--; currentimage = (currentimage + images.length) % images.length; hImageVIEwPic.setimageResource(images[currentimage]); } };
当我按下按钮然后插页式显示.我希望将间隙显示为一些图像.例如,在10日和20日之后或之后或之后5分钟等.请帮助我如何回忆间隙并在一些图像之后显示它.请帮我编写代码或编辑我的代码.我完全不知道如何才能完成这项任务.我会非常感激的.
解决方法 将您的adListener代码修改为interstitial.setAdListener(new AdListener() { @OverrIDe public voID onAdLoaded() { } @OverrIDe public voID onAdFailedToload(int errorCode) { long timestamp = System.currentTimeMillis(); if(timestamp > lastTimeAdFail + 120*1000) { AdRequest adRequest = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMulATOR).build(); // Load the interstitial ad again interstitial.loadAd(adRequest); } } @OverrIDe public voID onAdClosed () { AdRequest adRequest = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMulATOR).build(); // Load the interstitial ad again interstitial.loadAd(adRequest); } });
同时修改你的onclick监听器
VIEw.OnClickListener ibuttonChangeImageListener = new OnClickListener() { public voID onClick(VIEw v) { //Increase Counter to move to next Image currentimage++; currentimage = currentimage % images.length; hImageVIEwPic.setimageResource(images[currentimage]); if (interstitial.isLoaded()) { long timestamp = System.currentTimeMillis(); if(timestamp > lastTimeAdShown + 300*1000) { interstitial.show(); lastTimeAdShown = timestamp; } } else { long timestamp = System.currentTimeMillis(); if(timestamp > lastTimeAdFail + 120*1000) { AdRequest adRequest = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMulATOR).build(); // Load the interstitial ad. interstitial.loadAd(adRequest); lastTimeAdFail = timestamp; } } } };
编辑:将两个类变量定义为
private long lastTimeAdShown=System.currentTimeMillis();private long lastTimeAdFail=System.currentTimeMillis();总结
以上是内存溢出为你收集整理的android – 第二次如何调用interstitial全部内容,希望文章能够帮你解决android – 第二次如何调用interstitial所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)