I have a nested for loop. it works, kinda. It only reads the first if statement as true. It ignores all possible true statments after that.
for(int i = 0; i < inGroups.length; i++)
{
for(int g = 0; g < theGroups.length; g++)
{
if( inGroups[i].equals(theGroups[g]) )
{
gLV.setItemChecked(g, true);
}
}
}
Your code looks fine. As @Hot Licks mentioned, you should use a debugger and/or add print statements to see what’s going on.
Couple of general comments about your code:
Groupobject or whatever is in your arrays has implemented anequalsmethod otherwise it will always be false.setItemCheckedcan handle more than one value? If set is called twice does it just overwrite the previous value?Your code is very inefficient (O(N^2)). You could consider doing something like the following which is O(N). It won’t matter if the arrays are small of course. If you use this method then you will need to implement
hashCode()andequals()methods.Hope something here helps.