Puede alguien que me explique, ¿cuál es el problema?

Cuando me desplácese hacia abajo y luego de vuelta a la parte superior, mis artículos se han cambiado por otros elementos de la lista, y si me desplácese de nuevo, los artículos de nuevo, se cambian.

Este es mi Adaptador.

public class AcademicAdapter extends RecyclerView.Adapter<AcademicAdapter.AcademicVH> {
private LayoutInflater inflater;
private List<AcademicStatus> data;
public AcademicAdapter(List<AcademicStatus> data) {
this.data = data;
}
@Override
public AcademicVH onCreateViewHolder(ViewGroup parent, int viewType) {
inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.row_academic_level, parent, false);
return new AcademicVH(view);
}
@Override
public void onBindViewHolder(AcademicVH holder, int position) {
View view = inflater.inflate(R.layout.row_container_academic_level, holder.containerData, false);
TextView txtSubject = (TextView) view.findViewById(R.id.txtSubjectValue);
TextView txtGroup = (TextView) view.findViewById(R.id.txtGroupValue);
TextView txtStatus = (TextView) view.findViewById(R.id.txtStatusValue);
TextView txtFinalNote = (TextView) view.findViewById(R.id.txtFinalNoteValue);
TextView txtYear = (TextView) view.findViewById(R.id.txtYearValue);
txtSubject.setText(data.get(position).getSubject());
txtGroup.setText(data.get(position).getGroup());
txtStatus.setText(data.get(position).getStatus());
txtFinalNote.setText(data.get(position).getFinalNote());
txtYear.setText(data.get(position).getAcademicYear());
holder.containerData.addView(view);
}
@Override
public int getItemCount() {
return data.size();
}
public static class AcademicVH extends RecyclerView.ViewHolder {
private LinearLayout containerData;
public AcademicVH(View itemView) {
super(itemView);
containerData = (LinearLayout) itemView.findViewById(R.id.containerData);
}
}
}
InformationsquelleAutor Crash | 2016-04-14

5 Comentarios

  1. 8

    Intenta inicializar su punto de vista sobre RecyclerView.ViewHolder e inflar el layout en onCreateViewHolder() y no inflar de nuevo el diseño en onBindViewHolder().

    public class AcademicAdapter extends RecyclerView.Adapter<AcademicAdapter.AcademicVH> {
    private LayoutInflater inflater;
    private List<AcademicStatus> data;
    public AcademicAdapter(List<AcademicStatus> data) {
    this.data = data;
    }
    @Override
    public AcademicVH onCreateViewHolder(ViewGroup parent, int viewType) {
    View mView = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_academic_level, parent, false);
    AcademicVH mViewHold = new ViewHolder(mView);
    return mViewHold;
    }
    @Override
    public void onBindViewHolder(AcademicVH holder, int position) {
    final AcademicStatus mItems=this.data.get(position);
    holder.txtSubject.setText(mItems.getSubject());
    holder.txtGroup.setText(mItems.getGroup());
    holder.txtStatus.setText(mItems.getStatus());
    holder.txtFinalNote.setText(mItems.getFinalNote());
    holder.txtYear.setText(mItems.getAcademicYear());
    }
    @Override
    public int getItemCount() {
    return data.size();
    }
    public static class AcademicVH extends RecyclerView.ViewHolder {
    public LinearLayout containerData;
    public TextView txtSubject,txtGroup,txtStatus,txtFinalNote,txtYear;
    public AcademicVH(View itemView) {
    super(itemView);
    containerData = (LinearLayout) itemView.findViewById(R.id.containerData);
    txtSubject = (TextView) itemView.findViewById(R.id.txtSubjectValue);
    txtGroup = (TextView) itemView.findViewById(R.id.txtGroupValue);
    txtStatus = (TextView) itemView.findViewById(R.id.txtStatusValue);
    txtFinalNote = (TextView) itemView.findViewById(R.id.txtFinalNoteValue);
    txtYear = (TextView) itemView.findViewById(R.id.txtYearValue);
    }
    }
    }
    • Esta es la respuesta correcta. Gracias.
  2. 4

    a definir su elemento en el lugar equivocado, definir su punto de Vista en el interior de view holder y como a continuación

    public static class AcademicVH extends RecyclerView.ViewHolder {
    private LinearLayout containerData;
    public AcademicVH(View itemView) {
    super(itemView);
    TextView txtSubject = (TextView) view.findViewById(R.id.txtSubjectValue);
    TextView txtGroup = (TextView) view.findViewById(R.id.txtGroupValue);
    TextView txtStatus = (TextView) view.findViewById(R.id.txtStatusValue);
    TextView txtFinalNote = (TextView) view.findViewById(R.id.txtFinalNoteValue);
    TextView txtYear = (TextView) view.findViewById(R.id.txtYearValue);
    containerData = (LinearLayout) itemView.findViewById(R.id.containerData);
    }
    }

    otro truco, cuando se utiliza la condición (si) en su onBindViewHolder, usted debe completar con (más).

  3. 1

    Pondría recylerView en un NestedScroll Ver en su xml y agregar la propiedad nestedScrollingEnabled = false.

    Y en el adaptador de onBindViewHolder añadir esta línea

    final AcademicVH viewHolder = (AcademicVH)holder;

    Utilizar este viewHolder objeto con sus puntos de vista a setText o hacer cualquier tipo de eventos de Clic.

    e.g viewHolder.txtSubject.setText("Example");

  4. 0

    Problema es con la biblioteca
    compile 'com.android.support:recyclerview-v7:25.0.0'.
    Trate de usar
    compile 'com.android.support:recyclerview-v7:23.1.1'.

Dejar respuesta

Please enter your comment!
Please enter your name here