Parvez Wani
Parvez Wani

Reputation: 1

Sorting a custom ListView Adapter with multiple ArrayLists

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?

Upvotes: 0

Views: 26

Answers (1)

Stanislav Batura
Stanislav Batura

Reputation: 420

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

Upvotes: 1

Related Questions