2
In my app I have a ListView
which is provided through BaseAdapter
.
Then in the BaseAdapter
i have an IF statement to change the list background when the value of a variable was equal to the value of another global variable.
The problem is the BaseAdapter
changes the color when the values of the two variables are equal (this only happens once) and also changes the color in other wrong places!!!??? Here’s the method code getView
to see if anyone can help me:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
ViewHolder viewholder;
if(convertView == null){
LayoutInflater inflater = (LayoutInflater) contexto.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.textview_personalizado_dialog, null);
viewholder = new ViewHolder();
viewholder.estacao = (TextView) view.findViewById(R.id.textView1);
viewholder.horas = (TextView) view.findViewById(R.id.textView2);
view.setTag(viewholder);
} else {
viewholder = (ViewHolder) convertView.getTag();
}
String estacaoHora = lista.get(position);
String[] tokens = estacaoHora.split("/");
String valor1 = tokens[0];// Estação
String valor2 = tokens[1];// Hora
String valor3 = tokens[2];// Minutos
// Quando o valor da variavel "valor1" for igual ao valor da variavel "estacaoPesquisa" altera a cor de Background:
if (valor1.equals(estacaoPesquisa)){
// Altera a cor de fundo da lista:
viewholder.estacao.setBackgroundColor(contexto.getResources().getColor(R.color.verde_5));
viewholder.horas.setBackgroundColor(contexto.getResources().getColor(R.color.verde_5));
viewholder.estacao.setText(" " + valor1);
viewholder.horas.setText(valor2 + ":" + valor3);
} else {
viewholder.estacao.setText(" " + valor1);
viewholder.horas.setText(valor2 + ":" + valor3);
}
return view;
}
// Classe interna:
static class ViewHolder {
TextView estacao;
TextView horas;
}
Look at this reply maybe it’ll help.
– ramaral
Hello ramaral! The post you indicated is mine. Here my request for help is different, that is, I do not need to make a zebra list, I want to make a normal list but when the String value of a given list is equal to the value of a variable I want to change the Background color of that list (which will be unique at Listview)...
– Vitor Mendanha
I had not noticed that the post was yours. The problem here arises for the same reason. I see you did not understand the problem. I will post an answer.
– ramaral
Thank you ramaral. I’m waiting...
– Vitor Mendanha