gpt4 book ai didi

java - 想要在点击的每个按钮上显示插页式广告,但广告显示在一个按钮上

转载 作者:行者123 更新时间:2023-11-30 05:18:45 25 4
gpt4 key购买 nike

这是我的 main_activity 代码。我想在屏幕上可见的每个按钮上实现广告,并且在单击时应显示插页式广告。但它只在 btn_button 上显示广告。请指导我如何解决此问题。

public class MainActivity extends AppCompatActivity {
private InterstitialAd mInterstitialAd;

private InterstitialAd mInterstitialAd2;

Button btn_button,btn_button2,btn_button3,btn_button4,btn_button5;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}});

btn_button=(Button) findViewById(R.id.button);
btn_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i3=new Intent(MainActivity.this,Button.class);
startActivity(i3);

}
});

btn_button2=(Button) findViewById(R.id.button);
btn_button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i2=new Intent(MainActivity.this,Button.class);
startActivity(i2);

}
});
btn_button3=(Button) findViewById(R.id.button);
btn_button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(MainActivity.this,Button.class);
startActivity(i);

}
});
btn_button4=(Button) findViewById(R.id.button);
btn_button4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i4=new Intent(MainActivity.this,Button.class);
startActivity(i4);

}
});
btn_button5=(Button) findViewById(R.id.button);
btn_button5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i5=new Intent(MainActivity.this,Button.class);
startActivity(i5);

}
});

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

btn_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
});
mInterstitialAd2 = new InterstitialAd(this);
mInterstitialAd2.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd2.loadAd(new AdRequest.Builder().build());
btn_button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mInterstitialAd2.isLoaded()) {
mInterstitialAd2.show();
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
});
btn_button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
});
btn_button4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
});
btn_button5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
});
}
}

最佳答案

您有相同的按钮 ID,这就是为什么它只显示一个按钮,如 @Anon 提到的。

但实际上您并不需要如此多的插页式实例,因为您只使用一个广告单元。只需一个实例就足以在每个点击的按钮上展示广告。

但是...如果您尝试在每次点击时展示广告,您的 AdMob 帐户很快就会被停用。

关于java - 想要在点击的每个按钮上显示插页式广告,但广告显示在一个按钮上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59900797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com