Android Programming Starter Development Folder Manager development file filtering and sequencing-3

Source: Internet
Author: User

In front of the file operation and the main interface, and then the file filtering and sorting, we all know that in our equipment, whether it is a PC or mobile phone, there are always some of our

Invisible folder, that is the so-called hidden files, most of the hidden files, we do not have permission to operate, all for us is not necessary, must kill,

There is to file list sorting, aspects of the search, in fact, in the current folder management, do not know if we have found that the interface is the most right or left

A A-Z vertical arrangement of options, click on each letter, it will jump to the beginning of the Word file list items to go, this is a more useful thing, because the app is the

Before it is useless to new things, let's talk about rough ones.


File Dictionary sort:

Package com.example.util;/** * File sort processing * @author engineer-jsp * @date 2014.10.27 * */import java.io.file;import java.util. Comparator;public class Customcomparator implements comparator<file>{@Overridepublic int compare (File pFile1, File pFile2) {/** * 1. Compare folders (folders above the order of files) 2. Sort by A-Z dictionary 3. Compare folders and files 4. Compare files and folders */if (Pfile1.isdirectory () && Pfile2.isdirectory ()) {return Pfile1.getname (). Comparetoignorecase (Pfile2.getname ());} else {if (pfile1.isdirectory () && pfile2.isfile ()) {return-1;} else if (Pfile1.isfile () && pfile2.isdirectory ()) {return 1;} else {re Turn pfile1.getname (). Comparetoignorecase (Pfile2.getname ());}}}

Filter hidden files:

Package com.example.util;/** * filter hidden files * @author engineer-jsp * @date 2014.10.27 * */import java.io.file;import java.io.Fi Lefilter;import Java.io.filenamefilter;public class Customfilefilter implements FileFilter {public Boolean accept (File DirName) {if (!dirname.getname (). StartsWith (".")) {    return true;} Else{return false;}}}

Data sorting:

Package com.example.util;/** * Data sort * @author engineer-jsp * @date 2014.10.27 * */import java.io.file;import java.util.Ar Rays;import Java.util.collections;import Java.util.list;public class Filesort {public static file[] Sortfile (File[] files) {list<file> listfile = arrays.aslist (files); Collections.sort (ListFile, New Customcomparator ());   Make a sort by the specified rules file[] array = Listfile.toarray (new file[listfile.size ()); return array;}}

Example of sorting:



Sorting and filtering of files It's over, thank you.

Android Programming Starter Development Folder Manager development file filtering and sequencing-3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.