Here I want to call sortByDateModified() function and include the line Arrays.sort(files, filecomparatorByLastModified) inside that function. But the line Arrays.sort(files, filecomparatorByLastModified) is located into another function in public void getDir(String dirPath). How can I call a subfunction of another function from a function…
public void onClick(View v) { sortByDateModified(); }
public void getDir(String dirPath) {
myPath.setText("Location: " + dirPath);
item = new ArrayList<String>();
path = new ArrayList<String>();
File f = new File(dirPath);
File[] files = f.listFiles();
if(!dirPath.equals(root)) {
item.add(root);
path.add(root);
item.add("../");
path.add(f.getParent());
}
Arrays.sort(files, filecomparatorByLastModified);
Arrays.sort(files, filecomparator);
for(int i=0; i < files.length; i++) {
File file = files[i];
if(!file.isHidden() && file.canRead()){
path.add(file.getPath());
if(file.isDirectory()){
item.add(file.getName() + "/");
}
else { item.add(file.getName()); }
}
}
ArrayAdapter<String> fileList = new ArrayAdapter<String>(this, R.layout.row, item);
setListAdapter(fileList);
}
Ultimately, you would have to share either the directory or file array variable.