在addonitemtouchlistener中为recyclerview本机广告禁用onitemclick

snz8szmq  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(287)

在我的 recyclerView 我显示菜单项和 admob native ads 然后我补充说 addOnItemTouchListener 选择多个项目。

recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, recyclerView, new RecyclerItemClickListener.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                if (isMultiSelect)
                    multi_select(position);
                else
                    Toast.makeText(getApplicationContext(), "Details Page", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onItemLongClick(View view, int position) {
                if (!isMultiSelect) {
                    multiSelectList = new ArrayList<>();
                    isMultiSelect = true;
                    FVideosAdapter.enableOption(false);

                    if (mActionMode == null) {
                        mActionMode = startActionMode(mActionModeCallback);
                    }
                }
                multi_select(position);
            }
        }));

现在如何禁用 onItemClick 为了 UNIFIED_NATIVE_AD_VIEW_TYPE: 什么时候 isMultiSelecttrue ? 我不想包括 UNIFIED_NATIVE_AD_VIEW_TYPE 为了 multiselect .

public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {
        int viewType = getItemViewType(position);
        switch (viewType) {
            case UNIFIED_NATIVE_AD_VIEW_TYPE:
                UnifiedNativeAd nativeAd = (UnifiedNativeAd) videosPath.get(position);
                populateNativeAdView(nativeAd, ((UnifiedNativeAdViewHolder) holder).getAdView());
                break;
            case MENU_ITEM_VIEW_TYPE:
            default:
                final FolderVideoAdapterViewHolder folderVideoAdapterViewHolder = (FolderVideoAdapterViewHolder) holder;
                final FolderVideoModel folderVideoModel = (FolderVideoModel) videosPath.get(position);
                folderVideoAdapterViewHolder.videoName.setText(folderVideoModel.getFileName());
                folderVideoAdapterViewHolder.duration.setText(folderVideoModel.getDuration());
                folderVideoAdapterViewHolder.size.setText(folderVideoModel.getSize());

                if(selected_usersList.contains(videosPath.get(position)))
                    ((FolderVideoAdapterViewHolder) holder).videoPath.setBackgroundColor(ContextCompat.getColor(mContext, R.color.list_item_selected_state));
                else
                    ((FolderVideoAdapterViewHolder) holder).videoPath.setBackgroundColor(ContextCompat.getColor(mContext, R.color.list_item_normal_state));
        }
    }

详细的多选代码在这里

klsxnrf1

klsxnrf11#

要在ismultiselect为true时禁用unified\u native\u ad\u view\u type的onitemclick,您应该更改onitemclick方法,如下所示:

@Override
public void onItemClick(View view, int position) {
     int viewType = recyclerView.getAdapter().getItemViewType(position);
     if(viewType == UNIFIED_NATIVE_AD_VIEW_TYPE && isMultiSelect) {
         return;
     }

     if (isMultiSelect)
           multi_select(position);
     else
          Toast.makeText(getApplicationContext(), "Details Page", Toast.LENGTH_SHORT).show();
}

如果您想禁用adview中的long click以防止启动multiselect进程,请按如下所示更改long click方法:

@Override
public void onItemLongClick(View view, int position) {
    int viewType = recyclerView.getAdapter().getItemViewType(position);
    if(viewType == UNIFIED_NATIVE_AD_VIEW_TYPE) {
        return;
    }

    if (!isMultiSelect) {
        multiSelectList = new ArrayList<>();
        isMultiSelect = true;
        FVideosAdapter.enableOption(false);

        if (mActionMode == null) {
            mActionMode = startActionMode(mActionModeCallback);
        }
    }
    multi_select(position);
}

相关问题