我在 Environment.getExternalStorage() 中创建了一个名为“/My Webs”的目录。当应用程序启动时,它将目录文件和子目录的内容加载到一个列表中,我有一个按钮可以转到父目录,但我不希望用户高于根目录 /My Webs 目录。
这是我尝试过的:
private void upOneLevel(){
if(this.currentDirectory.getParent() != null || this.currentDirectory.getParent() != Environment.getExternalStorageDirectory().getPath() + "My Webs")
this.browseTo(this.currentDirectory.getParentFile());
}
private void browseTo(final File aDirectory){
// On relative we display the full path in the title.
if(this.displayMode == DISPLAYMODE.RELATIVE)
this.setTitle(aDirectory.getAbsolutePath() + " :: " +
getString(R.string.app_name));
if (aDirectory.isDirectory()){
this.currentDirectory = aDirectory;
fill(aDirectory.listFiles());
}else{
openFile(aDirectory);
}
}