I've created a directory at Environment.getExternalStorage() called '/My Webs'. When the app starts it loads the contents of the directory files and sub directories into a list I have a button to go to parent directories, but I don't want the user to go any higher than the root /My Webs directory.
Here is what I've tried:
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);
}
}
Your problem is here:
this.currentDirectory.getParent() != Environment.getExternalStorageDirectory().getPath() + "My Webs"
That is not how you compare strings in Java. Instead, use equals()
such as:
!this.currentDirectory.getParent().equals( Environment.getExternalStorageDirectory().getPath() + "My Webs" )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.