[android] Sort ArrayList of File path

출처 : http://stackoverflow.com/questions/5815060/sorting-arraylist-of-string-in-android

 

 

private ArrayList<String> _items = new ArrayList<String>();
.
.
.
public void sort()
{
  IgnoreCaseComparator icc = new IgnoreCaseComparator();
  java.util.Collections.sort(_items, icc);
}

private class IgnoreCaseComparator implements Comparator<String>
{
  public int compare(String $pathA, String $pathB)
  {
    File fileA = new File($pathA);
    File fileB = new File($pathB);
    return fileA.getName().compareToIgnoreCase(fileB.getName());
  }
}

 

[/storage/emulated/0/DCIM/PetGame/Human/20141030_171915.jpg, 
/storage/emulated/0/DCIM/PetGame/Text/20141030_171831.jpg, 
/storage/emulated/0/DCIM/PetGame/Text/20141030_171837.jpg, 
/storage/emulated/0/DCIM/PetGame/Text/20141030_171842.jpg]

 

[/storage/emulated/0/DCIM/PetGame/Text/20141030_171831.jpg, 
/storage/emulated/0/DCIM/PetGame/Text/20141030_171837.jpg, 
/storage/emulated/0/DCIM/PetGame/Text/20141030_171842.jpg, 
/storage/emulated/0/DCIM/PetGame/Human/20141030_171915.jpg]