【问题标题】:MoPub's ViewBinder fails placing TextView in native adMoPub 的 ViewBinder 在原生广告中放置 TextView 失败
【发布时间】:2014-07-28 08:24:53
【问题描述】:

我正在尝试使用本教程 https://github.com/mopub/mopub-android-sdk/wiki/Native-Ads-Integration 放置原生广告

即使我正确设置了视图活页夹(并且我看到它的值正确),logcat 也会打印出“尝试将文本(我的虚拟广告)添加到 null TextView。”

这是我在 BaseAdapter 中的 getView 的开始:

public View getView(int position, View convertView, ViewGroup parent) {
    if (moPubNativeResponse != null && mAdapterHelper.isAdPosition(position)) {
        View adView = mAdapterHelper.getAdView(convertView, parent, moPubNativeResponse, viewBinder, null);
        return adView;
    }

知道为什么吗?

【问题讨论】:

    标签: android mopub


    【解决方案1】:

    老问题(可能还有更旧的 MoPub 版本),但我今天在 LogCat 中遇到了这条消息,发现 NativeViewHolder 正在为原生广告的所有组件调用 addTextView() ——即使是那些未在请求参数中指定的组件。我通过简单地评论日志消息来解决它;您还可以在 update() 函数中为 TextViews 添加简单的空检查,而不是让它通过 AddTextView()。

    private void addTextView(@Nullable final TextView textView, @Nullable final String contents) {
        if (textView == null) {
            // MoPubLog.d("Attempted to add text (" + contents + ") to null TextView.");
            return;
        }
        ...
    }
    

    void update(@NonNull final NativeResponse nativeResponse) {
        if (titleView != null) addTextView(titleView, nativeResponse.getTitle());
        if (textView != null) addTextView(textView, nativeResponse.getText());
        if (callToActionView != null) addTextView(callToActionView, nativeResponse.getCallToAction());
        nativeResponse.loadMainImage(mainImageView);
        nativeResponse.loadIconImage(iconImageView);
    }
    

    注意:此解决方案仅在您将 MoPub SDK 作为库模块导入时才可行(因此可以编辑其源代码)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-06
      相关资源
      最近更新 更多