Android 广告使回收利用落后

Android 广告使回收利用落后,android,android-recyclerview,Android,Android Recyclerview,我把admob的横幅广告放在我的recyclerview中,当用户滚动时,它会滞后于我的recyclerview,下面是我所说的recyclerview的适配器代码。它会使recyclerview滞后,这有什么错呢 public class NewReleasesAdapter extends RecyclerView.Adapter< RecyclerView.ViewHolder> implements BillingProcessor.IBillingHandler {

我把admob的横幅广告放在我的recyclerview中,当用户滚动时,它会滞后于我的recyclerview,下面是我所说的recyclerview的适配器代码。它会使recyclerview滞后,这有什么错呢

public class NewReleasesAdapter extends RecyclerView.Adapter< RecyclerView.ViewHolder> implements BillingProcessor.IBillingHandler {
    public static final String TAG = NewReleasesAdapter.class.getSimpleName();
    private LayoutInflater mInflater;
    private Context mContext;
    private List<Release> mNewReleases;
    private DatabaseHelper mDatabaseHelper;
    // A game/release item view type.
    private static final int GAME_ITEM_VIEW_TYPE = 0;
    // The banner ad view type.
    private static final int BANNER_AD_VIEW_TYPE = 1;
    // Billing
    private BillingProcessor mBillingProcessor;
    private boolean mIsProVersion;
    // Ads
    private AdRequest mAdRequest;

    public NewReleasesAdapter(Context context) {
        mContext = context;
        mInflater = LayoutInflater.from(mContext);
        mDatabaseHelper = DatabaseHelper.getDatabaseHelper(mContext);

        mBillingProcessor = new BillingProcessor(
                mContext,
                "...",
                this);
        mBillingProcessor.initialize();
        mBillingProcessor.loadOwnedPurchasesFromGoogle();

        // Is in europe
        if (ConsentInformation.getInstance(mContext).isRequestLocationInEeaOrUnknown()) {
            switch (ConsentInformation.getInstance(mContext).getConsentStatus()) {
                case PERSONALIZED:
                    // Personalized ads
                    mAdRequest = new AdRequest.Builder().build();
                    break;
                case NON_PERSONALIZED:
                    // fall though to none Personalized ads
                default:
                    // None Personalized ads
                    Bundle extras = new Bundle();
                    // npa is short for "none personalized ads"
                    extras.putString("npa", "1");
                    mAdRequest = new AdRequest.Builder()
                            .addNetworkExtrasBundle(AdMobAdapter.class, extras)
                            .build();
                    break;
            }
        } else {
            // Personalized ads
            mAdRequest = new AdRequest.Builder().build();
        }
    }

    public void setNewReleases(List<Release> newReleases) {
        this.mNewReleases = newReleases;
        notifyDataSetChanged();
    }

    @Override
    public  RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch(viewType) {
            case GAME_ITEM_VIEW_TYPE:
                return new NewGameHolder(mInflater.inflate(R.layout.newly_added_game, parent, false));
            case BANNER_AD_VIEW_TYPE:
                return new ViewHolderAdMob(mInflater.inflate(R.layout.list_item_ad, parent, false), mAdRequest);
            default:
                return new NewGameHolder(mInflater.inflate(R.layout.newly_added_game, parent, false));
        }
    }

    @Override
    public int getItemViewType(int position) {
        // isn't pro version
        if (mIsProVersion) {
            if ((position + 1) % 4 == 0) {
                return BANNER_AD_VIEW_TYPE;
            }
        }
        return GAME_ITEM_VIEW_TYPE;
    }

    @Override
    public void onBindViewHolder(final  RecyclerView.ViewHolder holder, int position) {
        int viewType = getItemViewType(position);
        switch (viewType) {
            case BANNER_AD_VIEW_TYPE:
                // nothing to do
                break;
            case GAME_ITEM_VIEW_TYPE:
                // A lot of set texts
                break;
        }
    }

    @Override
    public int getItemCount() {
        if (mNewReleases == null) {
            return 0;
        }
        return mNewReleases.size();
    }

    @Override
    public void onProductPurchased(@NonNull String productId, @Nullable TransactionDetails details) {

    }

    @Override
    public void onPurchaseHistoryRestored() {

    }

    @Override
    public void onBillingError(int errorCode, @Nullable Throwable error) {
        // Log.d(TAG, "Error: " + errorCode + " : " + error.getMessage());
    }

    @Override
    public void onBillingInitialized() {
        mBillingProcessor.loadOwnedPurchasesFromGoogle();
        if (mBillingProcessor.isPurchased("gaming_reminder_pro")) {
            mIsProVersion = true;
            // Toast.makeText(mContext, "You're a pro user! Thanks!", Toast.LENGTH_SHORT).show();
        } else {
            // Show ads
            mIsProVersion = false;
        }
    }

    public BillingProcessor getBillingProcessor() {
        return mBillingProcessor;
    }

    public static class NewGameHolder extends RecyclerView.ViewHolder {
        public TextView name;
        public TextView summary;
        public TextView releaseDate;
        public TextView platforms;
        public TextView genres;
        public ImageView cover;
        public Button favorite;
        public ProgressBar coverProgressBar;
        public RelativeLayout newReleaseLayout;

        public NewGameHolder(View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.game_name);
            summary = itemView.findViewById(R.id.summary);
            releaseDate = itemView.findViewById(R.id.release_date);
            platforms = itemView.findViewById(R.id.platforms);
            genres = itemView.findViewById(R.id.genres);
            cover = itemView.findViewById(R.id.cover_image);
            favorite = itemView.findViewById(R.id.favorite);
            coverProgressBar = itemView.findViewById(R.id.cover_progress_bar);
            newReleaseLayout = itemView.findViewById(R.id.new_release);
        }
    }

    public static class ViewHolderAdMob extends RecyclerView.ViewHolder {
        public AdView mAdView;
        public ViewHolderAdMob(View view, final AdRequest adRequest) {
            super(view);
            mAdView = view.findViewById(R.id.adView);
            if (adRequest != null) {
                mAdView.loadAd(adRequest);
                mAdView.setAdListener(new AdListener(){
                    @Override
                    public void onAdLoaded() {
                        mAdView.setVisibility(View.VISIBLE);
                    }
                });
            }
        }
    }
}
public类newreleasesdapter扩展了RecyclerView.Adapter实现了BillingProcessor.IBillingHandler{
public static final String TAG=NewReleasesAdapter.class.getSimpleName();
私人停车场;
私有上下文;
私人租赁清单;
私有数据库助手mDatabaseHelper;
//游戏/发布项目视图类型。
私有静态最终整数游戏\项目\视图\类型=0;
//横幅广告视图类型。
私有静态最终整幅广告视图类型=1;
//账单
专用计费处理器mBillingProcessor;
私有布尔错误验证;
//广告
私人请求;
public NewReleasesAdapter(上下文){
mContext=上下文;
mInflater=LayoutInflater.from(mContext);
mDatabaseHelper=DatabaseHelper.getDatabaseHelper(mContext);
mBillingProcessor=新计费处理器(
McContext,
"...",
这),;
mBillingProcessor.initialize();
mBillingProcessor.loadOwnedPurchasesFromGoogle();
//他在欧洲
if(approvementInformation.getInstance(mContext.isRequestLocationIneAorUnknown()){
开关(ApproveInformation.getInstance(mContext.GetApproveStatus()){
个性化案例:
//个性化广告
mAdRequest=new-addRequest.Builder().build();
打破
案例非个性化:
//没有个性化的广告
违约:
//无个性化广告
Bundle extras=新Bundle();
//npa是“无个性化广告”的缩写
额外支出(“npa”、“1”);
mAdRequest=new AdRequest.Builder()
.addNetworkExtrasBundle(AdMobAdapter.class,附加)
.build();
打破
}
}否则{
//个性化广告
mAdRequest=new-addRequest.Builder().build();
}
}
public void setNewReleases(列出新版本){
this.mNewReleases=newReleases;
notifyDataSetChanged();
}
@凌驾
public RecyclerView.ViewHolder onCreateViewHolder(视图组父级,int-viewType){
开关(视图类型){
案例游戏\项目\视图\类型:
返回新的游戏持有者(mInflater.inflate(R.layout.new_added_game,parent,false));
案例标题\广告\视图\类型:
返回新的ViewHolderAdMob(mInflater.inflate(R.layout.list\u item\u ad,parent,false),mAdRequest);
违约:
返回新的游戏持有者(mInflater.inflate(R.layout.new_added_game,parent,false));
}
}
@凌驾
public int getItemViewType(int位置){
//这不是专业版吗
如果(错误批准){
如果((位置+1)%4==0){
返回横幅\广告\视图\类型;
}
}
返回游戏\项目\视图\类型;
}
@凌驾
public void onBindViewHolder(final RecyclerView.ViewHolder,int位置){
int viewType=getItemViewType(位置);
开关(视图类型){
案例标题\广告\视图\类型:
//无事可做
打破
案例游戏\项目\视图\类型:
//很多固定的文本
打破
}
}
@凌驾
public int getItemCount(){
if(mNewReleases==null){
返回0;
}
返回mNewReleases.size();
}
@凌驾
public void onProductPurchased(@NonNull String productId,@Nullable TransactionDetails){
}
@凌驾
PurchaseHistoryRestored()上的公共无效{
}
@凌驾
public void onBillingError(int errorCode,@Nullable Throwable error){
//Log.d(标记“Error:+errorCode+”:“+Error.getMessage());
}
@凌驾
在BillingInitialized()上公开作废{
mBillingProcessor.loadOwnedPurchasesFromGoogle();
if(mBillingProcessor.isPurchased(“gaming\u提醒\u pro”)){
错误验证=正确;
//Toast.makeText(mContext,“您是专业用户!谢谢!”,Toast.LENGTH\u SHORT.show();
}否则{
//展示广告
错误验证=错误;
}
}
公共计费处理器getBillingProcessor(){
返回mBillingProcessor;
}
公共静态类NewGameHolder扩展了RecyclerView.ViewHolder{
公共文本视图名称;
公共文本视图摘要;
公共文本视图发布日期;
公共文本视图平台;
公共文本视图类型;
公众视野封面;
公共按钮收藏;
公共ProgressBar coverProgressBar;
公共关系发布新版本布局;
公共新玩家持有者(查看项目视图){
超级(项目视图);
name=itemView.findviewbyd(R.id.game\u name);
summary=itemView.findviewbyd(R.id.summary);
releaseDate=itemView.findViewById(R.id.release\U日期);
平台=itemView.findViewById(R.id.platforms);
genres=itemView.findviewbyd(R.id.genres);
cover=itemView.findviewbyd(R.id.cover\u图像);
favorite=itemView.findviewbyd(R.id.favorite);
coverProgressBar=itemView.findViewById(R.id.coverProgressBar);
newReleaseLayout=itemView.findViewById(R.id.new\u release);
}
}
公共静态类ViewHolderAdMob扩展了RecyclerView.ViewHolder{
公共咨询中心;
公共ViewHolderAdMob(查看视图,最终地址){