onCreateViewHolder与android.support.v7中的onCreateViewHolder冲突

时间:2019-03-31 12:06:01

标签: java android android-gradle

我正在尝试在RecyclerView项目之间实施admob广告。我在以前的应用程序中做到了,并且运行良好,在此应用程序中出现此错误 http://prntscr.com/n5es3k

我尝试使用:

public class ItemCatgorySubListAdapter extends RecyclerView.Adapter<CustomViewHolder> rather than public class ItemCatgorySubListAdapter extends RecyclerView.Adapter<ItemCatgorySubListAdapter.CustomViewHolder> 

对我没用

public class ItemCatgorySubListAdapter extends RecyclerView.Adapter<ItemCatgorySubListAdapter.CustomViewHolder> {

    SettingsMain settingsMain;
    private ArrayList<catSubCatlistModel> list;
    private CatSubCatOnclicklinstener oNItemClickListener;
    private Context mContext;
    private static final int DEFAULT_VIEW_TYPE = 1;
    private static final int NATIVE_AD_VIEW_TYPE = 2;
    public ItemCatgorySubListAdapter(Context context, ArrayList<catSubCatlistModel> feedItemList) {
        this.list = feedItemList;
        this.mContext = context;
        settingsMain = new SettingsMain(context);
    }


    @Override
    public int getItemViewType(int position) {
        // Change the position of the ad displayed here. Current is after 5
        if ((position + 1) % 3 == 0) {
            return NATIVE_AD_VIEW_TYPE;
        }
        return DEFAULT_VIEW_TYPE;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder (ViewGroup viewGroup, int i) {
        View view;

        switch (i) {
            default:
                view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_cat_sub_cat, null);
                return new CustomViewHolder(view);

            case NATIVE_AD_VIEW_TYPE:
                view = LayoutInflater.from(viewGroup.getContext())
                        .inflate(R.layout.list_item_native_ad1, viewGroup, false);
                return new ViewHolderAdMob(view);

        }
    }




    @Override
    public void onBindViewHolder(CustomViewHolder holder, final int position) {

        final catSubCatlistModel feedItem = list.get(position);

        holder.titleTextView.setText(list.get(position).getCardName());
        holder.pathTV.setText(list.get(position).getPath());
        holder.priceTV.setText(list.get(position).getPrice());
        holder.locationTV.setText(list.get(position).getLocation());
        if (feedItem.isIs_show_countDown()) {
            holder.cv_countdownView.setVisibility(View.VISIBLE);
            holder.cv_countdownView.start(AdsTimerConvert.adforest_bidTimer(feedItem.getTimer_array()));
        }

一切正常,唯一的问题是在这里,正如我在http://prntscr.com/n5es3k之前所说的

1 个答案:

答案 0 :(得分:0)

您应该在RecyclerView.Adapter<RecyclerView.ViewHolder>返回onCreateViewHolder时扩展RecyclerView.ViewHolder

public class ItemCatgorySubListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>