我在投放 admob 广告时,在回收站视图中遇到了这个问题
问题:实际上是替换了列表中的项目并放置了广告
应用堆栈溢出成员之一推荐的解决方案后,出现问题
如何在android回收站视图中放置Admob本机高级广告?
这是我正在使用的代码:
@Override
public int getItemViewType(int position) {
if (position>1 && (position+1) % 4 == 0) {
return AD_TYPE;
} else {
return CONTENT_TYPE;
}
}
@Override
public int getItemCount() {
return articleList.size();
}
Run Code Online (Sandbox Code Playgroud)
这是完整的代码
public class ArticleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
private Context mContext;
private List<ArticleJson> articleList;
String titleoflist;
private static final int AD_TYPE = 2;
private static final int CONTENT_TYPE = 1;
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView txtTitle;
LinearLayout linearLayout;
private ArticleJson m_articleJson; …
Run Code Online (Sandbox Code Playgroud) android admob android-adapter android-recyclerview native-ads
您的应用包含公开的 Google Cloud Platform (GCP) API 密钥。有关详细信息,请参阅这篇 Google 帮助中心文章。
易受攻击的地点:
com.abc.Youtube_Player->onCreate
这是我的代码如何看待后端
public class Youtube_Player extends AppCompatActivity implements YouTubePlayer.OnInitializedListener {
// YouTube player view
public static final String GOOGLE_API_KEY = "<api key>";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_youtube__player);
// Initializing video player with developer key
mPlayerView.initialize(GOOGLE_API_KEY, this);
}
}
Run Code Online (Sandbox Code Playgroud) android youtube-api android-layout android-youtube-api google-cloud-platform
我想在 android 应用程序中我的回收站视图的每 3 个位置放置 admob 原生高级广告。
我想要 Admob 提供的模板。
https://github.com/googleads/googleads-mobile-android-native-templates
下面是原生广告的xml代码实现
<com.google.android.ads.nativetemplates.TemplateView
android:id="@+id/my_template"
<!-- this attribute determines which template is used. The other option is
@layout/gnt_medium_template_view -->
app:gnt_template_type="@layout/gnt_small_template_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Run Code Online (Sandbox Code Playgroud)
这是 Admob 的 Java 代码实现
MobileAds.initialize(this, "[_app-id_]");
AdLoader adLoader = new AdLoader.Builder(this, "[_ad-unit-id_]")
.forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
@Override
public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
NativeTemplateStyle styles = new
NativeTemplateStyle.Builder().withMainBackgroundColor(background).build();
TemplateView template = findViewById(R.id.my_template);
template.setStyles(styles);
template.setNativeAd(unifiedNativeAd);
}
})
.build();
adLoader.loadAd(new AdRequest.Builder().build());
}
Run Code Online (Sandbox Code Playgroud)
RecyclerView 适配器类:
public class ArticleAdapter extends RecyclerView.Adapter<ArticleAdapter.MyViewHolder>{
private …
Run Code Online (Sandbox Code Playgroud) android admob android-adapter android-recyclerview native-ads