How Android implements files in chronological order display

Source: Internet
Author: User

  1. <span style="FONT-SIZE:18PX;" >file[] Files =parentfile.listfiles (filefilter); //By Filefileter filter to get the desired type of sub-file under the Parentfile path
  2. arraylist<fileinfo> fileList = new arraylist<fileinfo> (); Deposit the required sub-file information into FileInfo
  3. For (int i = 0; i < files.length; i++) {
  4. File file = Files[i];
  5. FileInfo FileInfo = new FileInfo ();
  6. Fileinfo.name = File.getname ();
  7. Fileinfo.path = File.getpath ();
  8. Fileinfo.lastmodified= file.lastmodified ();
  9. Filelist.add (FileInfo);
  10. }
  11. Collections.sort (FileList, new Filecomparator ());   By overriding comparator implementation class Filecomparator, you can sort by file creation time.
  12. Report:
  13. Public class Filecomparator implements comparator<fileinfo> {
  14. public int compare (FileInfo file1, FileInfo file2) {
  15. if (file1.lastmodified < file2.lastmodified)
  16. {
  17. return-1;
  18. }Else
  19. {
  20. return 1;
  21. }
  22. }
  23. }
  24. Public FileFilter filefilter = new FileFilter () {
  25. Public Boolean accept (file file) {
  26. String tmp = File.getname (). toLowerCase ();
  27. if (Tmp.endswith (". mov") | | tmp.endswith (". jpg")) {
  28. return true;
  29. }
  30. return false;
  31. }
  32. };</span>

Similarly: By overriding the Compare method in the comparator implementation class, the display is arranged by file size, file name, and so on.

How Android implements files in chronological order display

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.