如何在android中选择文件夹?

Sus*_*gar 6 directory android picker filechooser android-widget

嗨,有一种方法可以选择用户想要在android中保存文件的文件夹.我查看了http://code.google.com/p/android-file-dialog/

它有选择文件的功能,但我想选择文件夹,请提供我可用的链接或示例.

Ree*_*eed 0

我在我的应用程序中使用了相同的源(非常确定),并且有一个代码块:

protected void onListItemClick(ListView l, View v, int position, long id) {
    if (file.isDirectory()) {
        selectButton.setEnabled(false);
        if (file.canRead()) {
            lastPositions.put(currentPath, position);
            getDir(path.get(position));
        } else {
            new AlertDialog.Builder(this)
                    .setIcon(R.drawable.icon)
                    .setTitle(
                            "[" + file.getName() + "] "
                                    + getText(R.string.cant_read_folder))
                    .setPositiveButton("OK",
                            new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which) {

                                }
                            }).show();
        }
    } else {
        selectedFile = file;
        v.setSelected(true);
        selectButton.setEnabled(true);
    }
}
Run Code Online (Sandbox Code Playgroud)

您只需编辑它处理的方式即可if (file.isDirectory())。我建议在您的 Activity 中声明一个值,如果该文件是一个目录并且它已经是 false,则将其boolean更改为该值。true然后如果该值为true,则遍历该目录。此外,当您将所述值更改为 时true,您需要致电selectButton.setEnabled(true). 我想说,这比编写自己的代码要简单得多。