I have a recycler view which has only a text view inside. In this text view, the user will load values from 0 to 5 (there may be decimals eg: 4.3).
I want the texts to have different colors depending on the number the user has entered. For example, numbers greater than 4.5 (4.6, 4.7, 4.8, 4.9, 5) will be assigned the color green.
How can I achieve this?
I attach the JAVA code of the adapter of my recycler view in which I am trying to change the colors (I do not get results)
@Override
public void onBindViewHolder(adapter_recycler_resultados.ViewHolderDatos
holder, int position){
holder.numeros.setText(array_recycler_numeros.get(position).getNumeros());
if(Integer.parseInt(array_recycler_numeros.get(position).getNumeros()) > 4.5){
holder.numeros.setTextColor(context.getResources().getColor(R.color.colorNotSelected));
}}
Why is what I'm doing wrong? How can I get the result I expect? Thank you for reading
It's something super simple. Try the following code:
I hope it helps you!