[英]how to add interstitial ads on cardView?
How to show interstitial ads?如何展示插页式广告? I have a custom cardView with many Intent that go to new Activity.我有一个自定义 cardView,其中包含许多 Intent,即 go 到新的 Activity。 The concept is like this, when user clicks the item on cardView, I want to display Interstitial ads before the new activity is appear.概念是这样的,当用户点击 cardView 上的项目时,我想在新活动出现之前显示插页式广告。 I want to know我想知道
2/How to show interstitial ads? 2/如何展示插页式广告? I have a custom cardView with many Intent that go to new Activity.我有一个自定义 cardView,其中包含许多 Intent,即 go 到新的 Activity。 The concept is like this, when user clicks the item on cardView, I want to display Interstitial ads before the new activity is appear.概念是这样的,当用户点击 cardView 上的项目时,我想在新活动出现之前显示插页式广告。 I want to know我想知道
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyHolder> {
private Context mContext;
private List<Recipes> mData;
private InterstitialAd mInterstitialdAd;
RecyclerViewAdapter(Context mContext, List<Recipes> mData){
this.mContext = mContext;
this.mData = mData;
}
@NonNull
@Override
public MyHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view ;
LayoutInflater layoutInflater = LayoutInflater.from(mContext);
view = layoutInflater.inflate(R.layout.cardview_recipe,viewGroup,false);
return new MyHolder(view);
}
@Override
public void onBindViewHolder(@NonNull final MyHolder myHolder, final int i) {
myHolder.recipeTitle.setText(mData.get(i).getRecipeName());
myHolder.img_recipe_thumbnail.setImageResource(mData.get(i).getThumbnail());
myHolder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(mContext,RecipeActivity.class);
intent.putExtra("RecipeName",mData.get(i).getRecipeName());
intent.putExtra("RecipeIngredients",mData.get(i).getRecipeIngredients());
intent.putExtra("RecipeMethodTitle",mData.get(i).getRecipeMethodTitle());
intent.putExtra("Recipe",mData.get(i).getRecipe());
intent.putExtra("Thumbnail",mData.get(i).getThumbnail());
mContext.startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return mData.size();
}
static class MyHolder extends RecyclerView.ViewHolder {
TextView recipeTitle;
CardView cardView;
ImageView img_recipe_thumbnail;
MyHolder(@NonNull View itemView) {
super(itemView);
recipeTitle = itemView.findViewById(R.id.recipe_text);
img_recipe_thumbnail = itemView.findViewById(R.id.recipe_img_id);
cardView = itemView.findViewById(R.id.cardview_id);
}
}
}
you can use adListner for open activity after ads closed.您可以在广告关闭后使用 adListner 进行开放活动。 ad your code into onAdClosed()
将您的代码广告到onAdClosed()
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
@Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
}
@Override
public void onAdOpened() {
// Code to be executed when the ad is displayed.
}
@Override
public void onAdClicked() {
// Code to be executed when the user clicks on an ad.
}
@Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
@Override
public void onAdClosed() {
// start your next activity Intent here..
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.