2013-02-25 23 views
0

我在Environment.getExternalStorage()上創建了一個名爲'/ My Webs'的目錄。當應用程序啓動時,它將目錄文件和子目錄的內容加載到列表中我有一個按鈕可以進入父目錄,但我不希望用戶比root/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); 
      } 
    } 
+0

嗨!歡迎來到StackOverflow! StackOverflow用於編程問題,這不是一個問題。如果問題是「我該如何做到這一點」,當您位於所需樹的頂部時,請禁用「按鈕進入父目錄」。 – CommonsWare 2013-02-25 01:22:37

回答

1

你的問題是在這裏:

this.currentDirectory.getParent() != Environment.getExternalStorageDirectory().getPath() + "My Webs" 

那不是你如何在Java中比較字符串。相反,使用equals()如:

!this.currentDirectory.getParent().equals(Environment.getExternalStorageDirectory().getPath() + "My Webs") 
+0

我已經這樣做過:)總是忘記==只是數值。 – RapsFan1981 2013-02-25 20:45:29