Kunal
Kunal

Reputation: 412

Android:Listing of files in a directory is random

I am saving the images in an app-specific folder and when i am trying to fetch the list of all the images of that folder and saving them in an array, the order of images which i am getting is random. I want the list of images in the order they are created i.e the newest one should come on top. Is there any function to achieve that. I am using this code to get the list of all files and storing them in an array.

 File[] listFile = downloadDir.listFiles();

Upvotes: 0

Views: 171

Answers (1)

Christophe Loeys
Christophe Loeys

Reputation: 196

You can always sort this Array by calling the sort method with a comparator that will sort the files based on their creation date. A way this could be achieved is explained here: Best way to list files in Java, sorted by Date Modified?

Upvotes: 1

Related Questions