getItemViewType不称为RecyclerView

时间:2018-09-11 17:54:12

标签: android

Quizásquisiste decir:al hacer un recyclerview no manda traer el getitemviewtype,algun ejemplo para comparar,nunca entra al getitemviewtype 进行recycleview时不发送getitemviewtype时,要比较一些示例,永远不要输入getitemviewtype

@Override
public int getItemViewType(int position) {
    Object item = list.get(position);
    Log.e(TAG, "getItemViewType: " +item);
    if (item instanceof NativeAppInstallAdView){
        Log.e("TYPODE", "instalacion");
        return NATIVE_APP_INSTALL_AD_VIEW_TYPE;
    }
    else if(item instanceof NativeContentAd){
        Log.e("TYPODE", "anuncio");
        return NATIVE_CONTENT_AD_VIEW_TYPE;
    }else {
        Log.e("TYPODE", "normal");
        return NOTIFICATION_VIEW_TYPE;
    }
}

1 个答案:

答案 0 :(得分:0)

您是否尝试过从getItemViewType()方法中调用onBindViewHolder(final RecyclerView.ViewHolder holder, final int position)方法?

//Your current method
@Override
public int getItemViewType(int position) {
    Object item = list.get(position);
    Log.e(TAG, "getItemViewType: " +item);
    if (item instanceof NativeAppInstallAdView){
        Log.e("TYPODE", "instalacion");
        return NATIVE_APP_INSTALL_AD_VIEW_TYPE;
    }
    else if(item instanceof NativeContentAd){
        Log.e("TYPODE", "anuncio");
        return NATIVE_CONTENT_AD_VIEW_TYPE;
    }else {
        Log.e("TYPODE", "normal");
        return NOTIFICATION_VIEW_TYPE;
    }
}

//Call getItemViewType() method from here
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
    switch (holder.getItemViewType()) {
        case NATIVE_APP_INSTALL_AD_VIEW_TYPE:
            ViewHolderApp viewHolderApp = (ViewHolderApp)holder;
            ...
            break;

        case NATIVE_CONTENT_AD_VIEW_TYPE:
            ViewHolderContent viewHolderContent = (ViewHolderContent)holder;
            ...
            break;
        case NOTIFICATION_VIEW_TYPE:
            ViewHolderView viewHolderView = (ViewHolderView)holder;                
            ...
            break;
    }
}

西班牙文:¿intentado llamar almétodogetItemViewType() desde delmétodoonBindViewHolder(final RecyclerView.ViewHolder holder, final int position)

Sugerencia:Intenta hacer tus preguntas eninglés