我想從最後降序到第一的文件夾和文件降序。但我不想從lastmodify()方法獲得。因爲如果我從任何文件夾中刪除文件。該文件夾數據首先獲取。這是我的模型類。獲取倒序的文件或文件夾存儲在SD卡中的Android
public class CallRecord implements Comparable<CallRecord>{
public String name;
public String time;
public String callType;
public String number;
public String filePath;
public String fileDuration;
public String folderName;
public String photoUri;
public boolean isStatic=false;
public String getPhotoUri() {
return photoUri;
}
public void setPhotoUri(String photoUri) {
this.photoUri = photoUri;
}
public String getFolderName() {
return folderName;
}
public void setFolderName(String folderName) {
this.folderName = folderName;
}
public boolean isStatic() {
return isStatic;
}
public void setStatic(boolean aStatic) {
isStatic = aStatic;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getCallType() {
return callType;
}
public void setCallType(String callType) {
this.callType = callType;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public String getFileDuration() {
return fileDuration;
}
public void setFileDuration(String fileDuration) {
this.fileDuration = fileDuration;
}
@Override
public int compareTo(CallRecord callRecord) {
Long date1 = Long.valueOf(this.getTime().substring(1, 5));
Long date2 = Long.valueOf(callRecord.getTime().substring(1, 5));
return (date2>date1 ? -1 : (date2==date1 ? 0 : 1));
}
}
你把文件夾名稱放入ArrayList ?? ??如果是,那麼你可以排序。然後顯示到列表中。 – Sach
@SachinShelar我使用列表將文件夾和文件存儲到列表中。然後我使用Comparator類來使用lastmodified()方法比較文件,但它首先返回我最近修改的那個文件夾。 –
SSALPHAX
然後就可以排序請提供您的模型類我將提供解決方案 – Sach