One way to use the file chooser in Android to sort files by their suffixes is by creating a CustomFilePickerDialog that extends the default FileChooserDialog and overrides its methods.
Here is an example:
public class CustomFilePickerDialog extends FileChooserDialog {
public CustomFilePickerDialog(Context context, File path) {
super(context, path);
}
@Override
protected void onFileSelected(File file) {
if (file.isDirectory()) {
setSelectedFile(file);
} else {
File[] files = getFileListAdapter().getFiles();
Arrays.sort(files, new Comparator<File>() {
@Override
public int compare(File file1, File file2) {
String suffix1 = file1.getName().substring(file1.getName().lastIndexOf(".") + 1);
String suffix2 = file2.getName().substring(file2.getName().lastIndexOf(".") + 1);
return suffix1.compareToIgnoreCase(suffix2);
}
});
getFileListAdapter().setFiles(files);
super.onFileSelected(file);
}
}
}
CustomFilePickerDialog dialog = new CustomFilePickerDialog(this, initialDirectory);
dialog.show();
This will sort the files by their suffixes when a file is selected.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-07-05 11:00:00 +0000
Seen: 9 times
Last updated: Oct 31 '21
How can Django Admin accommodate a variety of formats and locales for its input fields?
How can an array be passed using typo3 flexform xml and itemsProcConfig?
Is it possible to invoke an asynchronous function without using the await keyword?
How can metadata be linked to a series in Polars?
What is the process of utilizing the map function to map a pandas column using a dictionary?
How can the orientation of images be corrected during uploading using Plupload?