0

I've a custom ListView with 5 ArrayLists in the adaptor.

private ArrayList<String> name = new ArrayList<>();
private ArrayList<String> message = new ArrayList<>();
private ArrayList<Long> time = new ArrayList<>();
private ArrayList<String> imageId = new ArrayList<>();
private ArrayList<String> extras = new ArrayList<>();

ArrayList time contains remaining time in milliseconds. I want to display the list from lower to higher time left. If i just perform Collection.sort on a single ArrayList, others will remain unchanged. How can i sort all the ArrayLists accordingly with time.

I am passing all the ArrayLists to my custom adaptor at once.

Any suggestions?

1
  • Are the arraylists having a one-to-one relationship to each other? If so create a data model for it, and sort by the time field, the others will follow accordingly. Commented Mar 19, 2020 at 14:37

1 Answer 1

1

I think better to create a new class like this

class Class {
   String name;
   String message;
   Long time;
   String imageId;
   String extras;
}

Then creating single ArrayList then you can sort it by any fields by creating Comparator you want

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.