如何在Android中选择文件夹? [英] How to select folder in android?

查看:179
本文介绍了如何在Android中选择文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,有一种方法来选择文件夹的用户要保存文件中的机器人。我检查了 HTTP://$c$c.google.com/p / Android的文件对话框/

Hi there is a way to select folder where user want to save file in android . I check out http://code.google.com/p/android-file-dialog/

它的功能来选择文件,但我要选择的文件夹,请为我提供有用的链接或例子。

it has functionality to select file but i want to select folder , please provide me usable link or examples.

推荐答案

我用同样的源代码中我的应用程序(pretty的肯定),且有code块:

I used the same source in my app (pretty sure), and there is a block of code:

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

您只需要编辑它如何处理的如果(file.isDirectory())。我会建议声明布尔的价值在你的活动,你更改为如果该文件是一个目录,它是已经假的。那么,如果说价值是真实的,然后遍历目录。此外,当您更改表示值,你就需要调用 selectButton.setEnabled(真)。这将是相当多的不是使自己的code那么复杂,我会说。

You just have to edit how it handle's if (file.isDirectory()). I would recommend declaring a boolean value in your Activity which you change to true if the file is a directory and it is already false. Then if said value is true, then traverse the directory. Also when you change said value to true, you would need to call selectButton.setEnabled(true). This would be quite a bit less complicated than making your own code, I would say.

这篇关于如何在Android中选择文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆