I have various files in the internal memory, each one's finish his name with a number and his format, example:
/storage/emulated/0/packets
- File 1.x
- File 2.x
- ...
- File 11.x
I made a code to retrieve the files and sort in ascending order, but when the files are more than 10, the sort fail.
My code:
ArrayList<String> list;
public static boolean SetFileList(String directory){
list = new ArrayList<>();
if(DirectoryExist(directory)) { //DirectoryExist() verify if the parameter directory it's a true directory
File[] files = new File(directory).listFiles();
if (files == null) {
return false;
}
else if (files.length == 0) {
return false;
}
else {
Arrays.sort(files); //<------this method is supposed to sort
for (File file : files) {
list.add(file.getName());
}
return true;
}
}
else{
return false;
}
}
When I use the following code to show the files:
for(int i = 0; i < list.size(); i++){
Log.i("File", list.get(i));
}
Throws something like:
File: File 1.x
File: File 10.x
File: File 11.x
File: File 12.x
File: File 2.x
File: File 3.x
File: ...
But I want to show:
File: File 1.x
File: File 2.x
File: File 3.x
File: ...
File: File 10.x
File: File 11.x
File: File 12.x
Why is this happening?