我想知道如何在每次按下按鈕時顯示Admob插頁式廣告。我設法顯示插頁式廣告,但僅在第一次按下按鈕時才顯示。這裏是我的代碼:如何在每次單擊按鈕時顯示Admob插頁式廣告
package com.mycash.borgjake.mycash;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.view.View;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import static com.mycash.borgjake.mycash.R.styleable.View;
public class MainActivity extends AppCompatActivity {
private InterstitialAd mInterstitial;
Button btnClick;
Button btnWithdraw;
TextView txtBalance;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdView adView = (AdView)findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
adView.loadAd(adRequest);
btnClick = (Button) findViewById(R.id.button);
txtBalance = (TextView) findViewById(R.id.textView);
btnClick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String countValue = txtBalance.getText().toString();
int dblCountValue = Integer.parseInt(countValue);
if(mInterstitial.isLoaded()) {
mInterstitial.show();
}
dblCountValue++;
txtBalance.setText(String.valueOf(dblCountValue));
}
});
mInterstitial = new InterstitialAd(this);
mInterstitial.setAdUnitId("...");
AdRequest request = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
mInterstitial.loadAd(request);
}
public void onButtonClick(View v) {
if(v.getId() == R.id.button2) {
Intent i = new Intent(MainActivity.this, Withdraw.class);
startActivity(i);
}
}
}
感謝提前:)
呼叫mInterstitial.loadAd(要求);用戶關閉Interstitial添加後。 –
我該如何去做呢? – user3704212
mInterstitialAd.setAdListener(新AdListener的(){ @Override 公共無效onAdClosed(){// 繼續執行代碼 } 。}); –