0

I want to change the text color of the second column, all those that are less than 4.0 that turn red.

my viewHolder code:

@Override
public void onBindViewHolder(@NonNull ViewHolderDatos holder, int position) {

    holder.punto.setText(puntoNotaList.get(position).getPunto());
    holder.nota.setText(puntoNotaList.get(position).getNota());

    }
2
  • You can use setTextColor() and add if statement when your less than 4.0.
    – Crammeur
    Aug 1 '18 at 0:25
  • and how would the code be? Aug 1 '18 at 0:35
0

You can use setTextColor() in an if statement and when the value is less than 4.0 you set Color.RED otherwise Color.BLUE I think in your case.

In this example we change nota.

Example

...
if (Double.parseDouble(puntoNotaList.get(position).getNota()) < 4) {
    holder.nota.setTextColor(Color.RED);
} else {
    holder.nota.setTextColor(Color.BLUE);
}
...
2
  • That's the problem I have: What to put in / * Value you want compare * /? Aug 1 '18 at 0:40
  • I don't know because I need more code for this. And what is punto and nota wich one you want change color.
    – Crammeur
    Aug 1 '18 at 0:41
0

AdapterDatos.java

public class AdapterDatos extends RecyclerView.Adapter<AdapterDatos.ViewHolderDatos>{

Context context;
ArrayList<PuntoNota> puntoNotaList;

public AdapterDatos(Context context, ArrayList<PuntoNota> puntoNotaList) {
    this.context = context;
    this.puntoNotaList = puntoNotaList;
}


@NonNull
@Override
public ViewHolderDatos onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

    View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list,parent,false);
    ViewHolderDatos viewHolder = new ViewHolderDatos(itemView);
    return viewHolder;
}

@Override
public void onBindViewHolder(@NonNull ViewHolderDatos holder, int position) {

    holder.punto.setText(puntoNotaList.get(position).getPunto());
    holder.nota.setText(puntoNotaList.get(position).getNota());


    if((position % 2) == 0)
        holder.itemView.setBackgroundColor(0xFFeceff1);

    else
        holder.itemView.setBackgroundColor(0xFFffffff);


    }

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


public class ViewHolderDatos extends RecyclerView.ViewHolder {

    TextView punto, nota;

    public ViewHolderDatos(View item) {
        super(item);
        punto = item.findViewById(R.id.idPunto);
        nota = item.findViewById(R.id.idNota);
    }
}

}

4
  • Next time edit your code. Don't put it on answer this can mix us.
    – Crammeur
    Aug 1 '18 at 0:47
  • 1
    I sent you adapterData, if you need another files or codes I will send you immediately, and thanks for helping me. Aug 1 '18 at 0:50
  • And wich one you want to change color punto or nota
    – Crammeur
    Aug 1 '18 at 0:51
  • 1
    I want to change the nota. Aug 1 '18 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.