AlertDialog 不显示文件列表
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我意识到我有点晚了,你可能已经解决了你的问题,但我也遇到了同样的问题,我找出了问题所在。
显然,当您调用
.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 thesetItems()
declaration and turns theAlertDialog
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 beload_alert.create().show()
. Presumably that's a transcription error, though, because I thinkAlertDialog.Builder
doesn't have ashow()
method.即使我迟到发帖
但这是我尝试过的并且能够显示所有文件夹。
在我的代码中的某个时刻我有
谢谢
Even I am late in posting
but here is what i tried and was able to display all the folders.
and at some point in my code i have
Thanks