En el onBind con este código si me marca bien las personas ocupadas:
public class RecyclerViewAdapter extends RecyclerView.Adapter<Basico.RecyclerViewHolders> { private List itemList; private Context context;
public RecyclerViewAdapter(Context context, List<ItemObject> itemList) {
this.itemList = itemList;
this.context = context;
}
@Override
public Basico.RecyclerViewHolders onCreateViewHolder(ViewGroup parent, int viewType) {
View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view_list, null);
Basico.RecyclerViewHolders rcv = new Basico.RecyclerViewHolders(layoutView);
return rcv;
}
@Override
public void onBindViewHolder(MBasico.RecyclerViewHolders holder, int position) {
holder.ocupado.setText(itemList.get(position).getName());
holder.foto.setImageResource(itemList.get(position).getPhoto());
switch (position)
{
case 0:
if (p.getOcupado()==1)
{
holder.fondo.setBackgroundColor(Color.parseColor("#ffbe00"));
holder.name.setTextColor(Color.parseColor("#ffffff"));
}
break;
}
}
@Override
public int getItemCount() {
return this.itemList.size();
}
}
Pero en el onclick no me detecta bien si está ocupado o no, siempre empieza con pulsado =0 y luego pasa a 1, independientemente del valor devuelto por getOcupado().
public class RecyclerViewHolders extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView name;
public ImageView foto;
public RelativeLayout fondo;
public RecyclerViewHolders(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
name = (TextView) itemView.findViewById(R.id.name);
foto = (ImageView) itemView.findViewById(R.id.foto);
fondo = (RelativeLayout) itemView.findViewById(R.id.fondo_item);
}
@Override
public void onClick(View view) {
switch (getAdapterPosition())
{
case 0:
if (p.getOcupado()==1)
{
pulsado=1;
}
break;
}
if (pulsado == 0) {
pulsado = 1;
fondo.setBackgroundColor(Color.parseColor("#ffbe00"));
name.setTextColor(Color.parseColor("#ffffff"));
switch (getAdapterPosition()) {
case 0:
p.setOcupado(1);
break;
} else {
pulsado = 0;
fondo.setBackgroundColor(Color.parseColor("#ffffff"));
name.setTextColor(Color.parseColor("#ffbe00"));
switch (getAdapterPosition()) {
case 0:
p.setOcupado(0);
break;
}
}
}
}