Error selecting recycler view item

0

I do not understand why when I select an item from the recycler view, it also marks me an element from the bottom.

Top:

Bottom:

The code I have is the following:

public class adapter_archivos extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

Context context;
List<Object> mitems;
public static List<String> list = new ArrayList<>();

public adapter_archivos(Context context, List<Object> mitems) {
    this.context = context;
    this.mitems = mitems;
}

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.vista_list, parent, false);

    return new listaarchivos_holer(view);
}

public static class listaarchivos_holer extends RecyclerView.ViewHolder {

    TextView nombre;
    TextView peso;
    ImageView check;

    public listaarchivos_holer(View itemView) {
        super(itemView);

        nombre = (TextView) itemView.findViewById(R.id.nombre_archivo);
        peso = (TextView) itemView.findViewById(R.id.peso_archivo);
        check = (ImageView) itemView.findViewById(R.id.check);
    }

}

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {

    final listaarchivos_holer listaarchivos_holer = (listaarchivos_holer) holder;
    final contenedor_archivos contenedor_archivos = (contenedor_archivos) mitems.get(position);

    listaarchivos_holer.nombre.setText(contenedor_archivos.getNombre());
    listaarchivos_holer.peso.setText(contenedor_archivos.getPeso());
    listaarchivos_holer.check.setImageResource(contenedor_archivos.getCheck(contenedor_archivos.check));

    listaarchivos_holer.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            recibirPos(contenedor_archivos.getNombre(), listaarchivos_holer.check);

        }
    });

}

public void recibirPos(String nombre, ImageView nn) {

    String e = null;
    boolean agregar = true;

    for (int cont = 0; cont < list.size(); cont++) {

        e = list.get(cont);

        if (nombre.equalsIgnoreCase(e)) {
            agregar = false;
            list.remove(nombre);
            nn.setVisibility(View.INVISIBLE);
            break;
        }
    }
    if (agregar) {
        list.add(nombre);
        nn.setVisibility(View.VISIBLE);
    }

    Log.e("prueba", "" + list);

}

@Override
public int getItemCount() {
    return mitems.size();
}

}

What I'm trying to do is that when you touch an element of the recycler, I save the name in a variable and then delete that file (that's how to do it), but I also try to make it show an image when they touch it of a check to know what element they have selected, but when I select the first one, another one is also marked in the lower part of the recycler, how can I make it so that it only marks or activates the image in the option that it has touched?

    
asked by Leonardo Henao 18.09.2017 в 17:26
source

1 answer

0

Hello in the container_file object you can add a checked variables at the time of doing the bind of the view ask

nn.setVisibility(contenedor_archivos.isChecked() ? View.VISIBLE : View.INVISIBLE);

Do not forget to give the checked value when it needs to be changed.

greetings

    
answered by 18.09.2017 в 17:32