【问题标题】:How do I Lock user in home directory如何将用户锁定在主目录中
【发布时间】:2013-02-10 02:36:03
【问题描述】:

我在 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);
            }
    }

【问题讨论】:

  • 嗨!欢迎来到 StackOverflow! StackOverflow 用于编程问题,这不是问题。如果问题是“我该怎么做”,请在您位于所需树的顶部时禁用“转到父目录的按钮”。

标签: java android list directory


【解决方案1】:

你的问题在这里:

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

这不是您在 Java 中比较字符串的方式。而是使用equals(),例如:

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

【讨论】:

  • 我以前做过 :) 总是忘记 == 仅用于数值。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-11
  • 2017-10-30
  • 2010-12-01
  • 2015-03-26
  • 2017-09-19
相关资源
最近更新 更多