Daniel,
To implement this color change in Listview, make a customAdapter that extends the Arrayadapter, so inside it you implement this color change.
public class ArrayTeste extends ArrayAdapter {
List<Objeto> lista;
Context contexto;
public ArrayTeste(Context context, int resource, List<Objeto> lista) {
super(context, resource, lista);
this.lista = lista;
this.contexto = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Objeto objeto = lista.get(position);
if(objeto.isStatus()){
int cor = Color.parseColor("blue");
convertView.setBackgroundColor(cor);
}
return super.getView(position, convertView, parent);
}
public class Objeto{
private String Nome;
public String getNome() {
return Nome;
}
public void setNome(String nome) {
Nome = nome;
}
public boolean isStatus() {
return Status;
}
public void setStatus(boolean status) {
Status = status;
}
private boolean Status;
}
}
In the end I set an example class just so you understand.
Using this Adapter, in your Activity call
meuAdapter.clear();
meuAdapter.addAll(listaObjetosAtualizados);
The command notifyDataSetChanged()
will only update an item that has been added or removed, it will not update a View that is already in display.
Your Adapter already has the code that changes the line color ? Your question is to update the list ?
– Lucas Queiroz Ribeiro
Try the notifyDataSetChanged(); You can call it inside the Adapter itself or in your Activity by doing: Adapter.notifyDataSetChanged();
– Caique Oliveira