【问题标题】:Android: show a folderAndroid:显示一个文件夹
【发布时间】:2015-02-17 08:46:54
【问题描述】:

我在我的 Android 应用程序的外部存储中保存了一个文件夹。 我知道在这种模式下读取一个文件:

File storage = Environment.getExternalStorageDirectory();
File file = new File(storage,"/folder/filename.wav");

但我想通过单击按钮来显示我的应用程序文件夹中的所有文件。

你能帮帮我吗?

【问题讨论】:

  • show all files in folder on my app with the click of a botton->太宽泛

标签: android directory storage external show


【解决方案1】:

像这样使用它:

    yourButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            File file = new File(pathToDirectory);
            StringBuffer sb = new StringBuffer();
            if (file.exists() && file.isDirectory()) {
                for (String s : file.list()) {
                    sb.append(s + " ");
                }
            }
            YourActivity.this.setFileListString(sb.toString());
        }
    });

如果您想循环浏览文件对象,请使用 File 而不是 String。在您的活动中,您需要一种将字符串写入 TextView 或其他内容的方法。

【讨论】:

  • 这样我文件夹中的所有文件都会显示在我的应用程序的活动中吗?
  • 用您的按钮对象切换“yourButton”。YourActivity 也是如此。
猜你喜欢
  • 2013-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-11
  • 2021-02-17
  • 1970-01-01
  • 1970-01-01
  • 2013-06-19
相关资源
最近更新 更多