向下滚动并向上滚动时,RecyclerView返回错误的位置

时间:2017-09-24 08:24:16

标签: java android android-recyclerview

我有的recyclelerView有一个viewHolder和很多viewType,当我向下滚动并再次向上滚动时我会得到不同的recyclerView位置行为,我不知道我在这里缺少什么?

这是我的完整适配器。

@Override
public int getItemViewType(int position) {

    int viewType = 0;

    if (position == 0) {
        viewType = 0;
    }else if (position == 1){
        viewType = 1;
    }else if (position == 2){
        viewType = 2;
    } else if (position == 3){
        viewType = 3;
    }

    return viewType;

}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_notification, parent, false);
    switch (viewType){
        case 0:
            return new MyViewHolder(v);
        case 1:
            return new MyViewHolder(v);
        case 2:
            return new MyViewHolder(v);
        case 3:
            return new MyViewHolder(v);
        default:
            return new MyViewHolder(v);
    }

}

@Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
    final DataNotifications dataNotifications = list.get(position);
    int type = Integer.valueOf(dataNotifications.getStatue());
    ...
    switch (getItemViewType(type)){
        case 0:
            MyViewHolder myViewHolder = (MyViewHolder) holder;
            ......
            break;
        case 1:
            MyViewHolder myViewHolderAccepted = (MyViewHolder) holder;
            .....
            break;
        case 2:
            MyViewHolder myViewHolderPending = (MyViewHolder) holder;
            ......
            break;
        case 3:
            MyViewHolder myViewHolderRefused = (MyViewHolder) holder;
            ....
            break;
    }

//        Glide.with(context).load(dataNotifications.getThumbnail()).into(holder.thumnail);


    }

这个问题对我来说可能是什么情况?提前谢谢!

0 个答案:

没有答案