W moim {X0}} Wyświetlam element menu i admob native ads Następnie dodałem addOnItemTouchListener, aby wybrać wiele elementów.

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);
            }
        }));

Teraz jak wyłączyć onItemClick dla UNIFIED_NATIVE_AD_VIEW_TYPE:, gdy isMultiSelect jest true? Nie chcę zawierać UNIFIED_NATIVE_AD_VIEW_TYPE dla 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));
        }
    }

Szczegółowy kod wieloosobowy jest Oto

1
sanoj lawrence 21 listopad 2020, 08:39

1 odpowiedź

Najlepsza odpowiedź

Aby wyłączyć oniteMclick dla Unified_native_ad_view_type, gdy IsMultiselect jest prawdziwy, należy zmienić swoją metodę OniTemClick , jak poniżej:

@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();
}

A jeśli chcesz wyłączyć długie kliknięcie z Adview, aby zapobiec rozpoczęciu procesu multiselect zmienić OniTemlongClick metodę jak poniżej:

@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);
}
2
MariosP 25 listopad 2020, 10:25