Good afternoon, I am developing an Android App that must have the following behavior in one of its Activities:
-There is a Main Articles List (listaDetalle) and a Secondary List (listaDetalleForSave).
When the child list has at least one occurrence of each element of the parent list, a TextView
should change Color and Text value, for this, I made a small method isComplete()
that performs the comparison as follows:
public boolean isComplete()
{
boolean res = false;
if(listaDetalleForSave.containsAll(listaDetalle))
{res = true;}
return res;
}
However, despite the fact that there is at least one occurrence of each element of list 2 in list 1 (I checked it in Debug mode), the method containsAll
always returns False.
I tend to imagine that it is because the objects are not actually equal (The value of one of their attributes changes). I tried overriding the equals method of the class but it didn't help.
@Override
public boolean equals(Object obj)
{
DetCFStock objeto = (DetCFStock) obj;
if(this.getID() == objeto.getID())
{
return true;
}
else return false;
}
Could you help me with this?
Fixed. The equals method was returning false for comparing Strings with == I changed the comparison to, excuse me, equals, and it worked.