Code example for File

Methods: listFiles

0
    /** 
     * Change the adapted directory for a new one 
     * @param directory     New file to adapt. Can be NULL, meaning "no content to adapt". 
     */ 
    public void swapDirectory(File directory) {
        mDirectory = directory;
        mFiles = (mDirectory != null ? mDirectory.listFiles() : null);
        if (mFiles != null) {
            Arrays.sort(mFiles, new Comparator<File>() {
                @Override 
                public int compare(File lhs, File rhs) {
                    if (lhs.isDirectory() && !rhs.isDirectory()) {
                        return -1; 
                    } else if (!lhs.isDirectory() && rhs.isDirectory()) {
                        return 1; 
                    } 
                    return compareNames(lhs, rhs);
                } 
             
                private int compareNames(File lhs, File rhs) {
                    return lhs.getName().toLowerCase().compareTo(rhs.getName().toLowerCase());