I got question on Comparator - I need to sort my ArrayList<Integer> numbersToSort, which keeps numbers- links to competition.participant.get(numbers.get(index)) - so I have a main Object - competition which has a List of participants object. So, my ArrayList<Integer> numbersToSort keeps which numbers of competition.participants should I use. The only way I figured how to sort my ArrayList<Integer> numbersToSort (which I later will feed to my ListView Adapter) is to make another "parallel"List<Participants> where I shall copy participants from main object, competition and store in them their number in ArrayList<Integer> numbersToSort so I can later assemble a new ArrayList<Integer> sortedNumbers from sorted List<Participant> participants. Are you still there ?:)
public class ParticipantIndexComparator implements Comparator<Integer> {
final List<Participant> participants;
public ParticipantIndexComparator(ArrayList<Integer> numbersToSort) {
participants=new ArrayList<Participant>();
for (int i=0;i<numbersToSort.size();i++)
{ participants.add(i,competition.participant.get(numbersToSort.get(i))); participants.get(i).comparator=numbersToSort.get(i);}
}
@Override
public int compare(Integer i1, Integer i2) {
long l1 = participants.get(i1).kpTime.get(kpSelected);
//time from selected checkpoint
long l2 = participants.get(i2).kpTime.get(kpSelected);
return (long) compare(l1, l2);
}
}
well, the problem is the last return (long) compare(l1, l2); - yes, I know it's not right but it's the 30th attempt :) please correct what's wrong