AlertDialog 不显示文件列表

发布于 2024-12-08 21:07:17 字数 800 浏览 0 评论 0原文

AlertDialog.Builder load_alert = new AlertDialog.Builder(this);
            File list = new File("data/data/project/databases/");
            if(!list.exists() || !list.isDirectory()){
                return;
            }
            String [] fileList = list.list();

            load_alert.setMessage("Please select");     
            load_alert.setItems(fileList, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    Toast toast = Toast.makeText(getApplicationContext(), "test", Toast.LENGTH_LONG);
                    toast.show();
                }
            }); 
            load_alert.show();

这应该将我的数据库文件夹的内容显示到警报对话框中。我已经检查了 fileList 数组,它正在被填充。由于某种原因,它只是不通过 setItems 显示。有什么想法吗?

AlertDialog.Builder load_alert = new AlertDialog.Builder(this);
            File list = new File("data/data/project/databases/");
            if(!list.exists() || !list.isDirectory()){
                return;
            }
            String [] fileList = list.list();

            load_alert.setMessage("Please select");     
            load_alert.setItems(fileList, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    Toast toast = Toast.makeText(getApplicationContext(), "test", Toast.LENGTH_LONG);
                    toast.show();
                }
            }); 
            load_alert.show();

This is supposed to display the content of my database folder into an alertdialog. I've checked the fileList array, and it is being populated. For some reason it just isn't displaying via setItems. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

娇女薄笑 2024-12-15 21:07:17

我意识到我有点晚了,你可能已经解决了你的问题,但我也遇到了同样的问题,我找出了问题所在。

显然,当您调用 .setMessage() 时,它会覆盖 setItems() 声明并将 AlertDialog 转换为消息对话框。相反,调用 .setTitle() 来设置对话框的标题。

另外,在您的示例中,您似乎没有调用 .create(),因此它应该是 load_alert.create().show()。不过,这可能是一个转录错误,因为我认为 AlertDialog.Builder 没有 show() 方法。

I realize I'm a little late to the ballgame and that you have probably already solved your problem, but I was having the same issue and I figured out what the problem was.

Apparently, when you call .setMessage(), that overrides the setItems() declaration and turns the AlertDialog into a message dialog. Instead, call .setTitle() to set the title of the dialog.

Also, in your example you don't seem to call .create(), so it should be load_alert.create().show(). Presumably that's a transcription error, though, because I think AlertDialog.Builder doesn't have a show() method.

許願樹丅啲祈禱 2024-12-15 21:07:17

即使我迟到发帖
但这是我尝试过的并且能够显示所有文件夹。

AlertDialog.Builder listAlert = new AlertDialog.Builder(this);
        String [] filelist = path.list();
        listAlert.setTitle("Select Definition File");
        listAlert.setItems(filelist, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Stuffs to do after you have selected folder or file.

        }
    }).show();

在我的代码中的某个时刻我有

private File path = new File(Environment.getExternalStorageDirectory()+"");

谢谢

Even I am late in posting
but here is what i tried and was able to display all the folders.

AlertDialog.Builder listAlert = new AlertDialog.Builder(this);
        String [] filelist = path.list();
        listAlert.setTitle("Select Definition File");
        listAlert.setItems(filelist, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Stuffs to do after you have selected folder or file.

        }
    }).show();

and at some point in my code i have

private File path = new File(Environment.getExternalStorageDirectory()+"");

Thanks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文