我试图显示5个按钮点击后的间隙广告,下面是我的代码,这是不起作用的,请有人告诉我如何解决这个问题。我试过两种方法,都不管用。
附言:我是android开发新手。
第一个代码
int counter = 0;
...
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Button play_video = (Button) rootView.findViewById(R.id.play_video);
play_video.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (counter == 5) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
counter = 0;
} else {
counter++;
stream(vidData);
getDialog().dismiss();
}
if (!mInterstitialAd.isLoading() && !mInterstitialAd.isLoaded()) {
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
}
}
}
});
第二守则(共享偏好)
private int counter = 0;
.....
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Button play_video = (Button) rootView.findViewById(R.id.play_video);
play_video.setOnClickListener(new View.OnClickListener() {
Context context = getActivity();
SharedPreferences preferences = context.getSharedPreferences("MyPreferences", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
int counter = preferences.getInt("CounterR", 0);
@Override
public void onClick(View v) {
if (mInterstitialAd.isLoaded() & counter >= 5) {
counter = 0;
mInterstitialAd.show();
} else {
counter++;
stream(vidData);
getDialog().dismiss();
}
editor.putInt("CounteR", counter);
editor.commit();
if (!mInterstitialAd.isLoading() && !mInterstitialAd.isLoaded()) {
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
}
}
});
更新完整代码
private int counter = 0;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.vid_alert, container, false);
close_dialog = (Button) findViewById(R.id.close_dialog);
mInterstitialAd = new InterstitialAd(getActivity());
mInterstitialAd.setAdUnitId("xxxxxxxxxxxxxxxxxx");
AdRequest adRequest = new AdRequest.Builder().build();
// Load ads into Interstitial Ads
mInterstitialAd.loadAd(adRequest);
// Create and set AdListener for interstitial
mInterstitialAd.setAdListener(new AdListener() {
public void onAdClosed() {
// When user closes ad end this activity (go back to first
// activity)
finish();
}
private void finish() {
// TODO Auto-generated method stub
}
});
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
Bundle mArgs = getArguments();
final String vidData = mArgs.getString("vid_data");
final String vidID = mArgs.getString("vid_id");
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Context context = getActivity();
SharedPreferences preferences = context.getSharedPreferences("MyPreferences", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
Button stream_video = (Button) rootView.findViewById(R.id.stream_video);
stream_video.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (counter == 5) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
counter = 0;
} else {
// means interstitial not yet loaded,so make a load
// request
AdRequest newadRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(newadRequest);
// as nothing will happen when we get inside this else
// statement, you should call the stream method from
// here too
streamFB(vidData);
getDialog().dismiss();
}
} else {
counter++;
streamFB(vidData);
getDialog().dismiss();
}
}
});
Button close_dialog = (Button) rootView.findViewById(R.id.close_dialog);
close_dialog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (counter == 5) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
counter = 0;
} else {
// means interstitial not yet loaded,so make a load
// request
AdRequest newadRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(newadRequest);
// as nothing will happen when we get inside this else
// statement, you should call the stream method from
// here too
getDialog().dismiss();
}
} else {
counter++;
getDialog().dismiss();
}
}
});
// Do something else
return rootView;
试试这个,如果它不起作用,很可能你的广告代码中有问题。
int counter = 0;
...
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Button play_video = (Button) rootView.findViewById(R.id.play_video);
play_video.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (counter != 5) {
counter++;
stream(vidData);
getDialog().dismiss();
}
else if (counter ==5){
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
counter = 0;
}
}
if (!mInterstitialAd.isLoading() && !mInterstitialAd.isLoaded()) {
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
}
}
}
});
}
在mInterstitialAd.show()之后删除计数器=0;从if条件中删除计数器并将其放置在onAdCloses()函数中,参见下面的示例:mInterstitialAd.setAdListener(new AdListener(){@覆盖公共空onAdCloses(){Request estNewInterstials();计数器=0; start NewGame(); } });
问题在于您的逻辑,else部分应该与外部if一起提供,请检查下面的代码:
if (counter == 5) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequest);
counter = 0;
}else{
// means interstitial not yet loaded,so make a load request
AdRequest newadRequest = new AdRequest.Builder().build();
mInterstitialAd.loadAd(newadRequest);
// as nothing will happen when we get inside this else statement, you should call the stream method from here too
stream(vidData);
getDialog().dismiss();
}
}else {
counter++;
stream(vidData);
getDialog().dismiss();
}
在onclick方法中移动此代码。让我知道它是否有效,直接在stackoverflow上编辑,请检查语法错误,可能有一个或两个。
在这个图像中有8个按钮。现在我在这个应用程序上使用测试广告单元。这个活动我有8个按钮,每个按钮都与有针对性的活动相联系。我的问题是,当我单击这8个按钮中的任何按钮时,它会显示admob插播广告并发送到目标活动,但当我关闭目标活动并再次返回main_activity并单击这8个按钮中的任何按钮时,admo插播广告不会显示,但在按钮上单击它会打开目标活动。我想在每次点击按钮时显示广告插播广告。这是怎么
我是android开发的新手,我试图在点击5次按钮后显示中间广告,下面是我的代码,它不起作用,请有人指导我如何解决这个问题。
我正在完成一个视频应用程序,我在离开视频activity时显示间隙广告。我只想每X分钟显示一次,但似乎每次我离开那个屏幕时它都在显示。 这是我的activity密码。 onCreate: onbackpressed: 当然,在admob中是这样设置的: 注意:我的应用程序没有发布,所以它正在显示“预览”o“示例”。我正在使用我的广告单元ID: 谢谢,
我成功地在我的应用程序中实现了AdMob中间广告,但唯一的问题是它们不可点击。 下面是我的AdMob.java类: 和MainPageActivity.java文件: 我不知道当用户升级并按下播放按钮(这将引导他进入下一个级别)时,该如何显示间隙广告。当他按下home键时,间隙广告就会出现,这会把他带到MainActivity屏幕上。 有人能帮我把广告点击一下吗?另外,有什么建议,如何添加的间隙广
我想在一定的时间间隔后,在主要活动上添加一个间隙广告。我搜索,似乎没有参考代码这样做。感谢你的帮助我该怎么做?任何示例代码都将是有用的。多谢了。
链接到我正在尝试刮取的页面: https://www.nytimes.com/reviews/dining 因为这个页面有一个“show more”按钮,所以我需要Selenium自动反复单击“show more”按钮,然后以某种方式使用Beauty soup来获取页面上每个餐厅评论的链接。在下面的照片中,我想获取的链接位于https://...onigiri.html" 迄今为止的代码: 我如何