android如何在内存中使用警报对话框创建新文件夹
我想在按钮上创建新文件夹,单击“使用警报”对话框以用户名称命名并在目录上创建文件夹 如何在对话框栏上创建新文件夹 请告诉我我该怎么做??如何使用对话框创建新文件夹 这是我要创建文件夹的文件路径:android如何在内存中使用警报对话框创建新文件夹,android,Android,我想在按钮上创建新文件夹,单击“使用警报”对话框以用户名称命名并在目录上创建文件夹 如何在对话框栏上创建新文件夹 请告诉我我该怎么做??如何使用对话框创建新文件夹 这是我要创建文件夹的文件路径: File photos = new File(getFilesDir(),"photos"); photos.mkdir(); 创建文件夹的代码看起来正确。要从用户处获取文件夹名称,您需要执行以下操作: AlertDialog.Builder alert = new AlertDialog.Bu
File photos = new File(getFilesDir(),"photos");
photos.mkdir();
创建文件夹的代码看起来正确。要从用户处获取文件夹名称,您需要执行以下操作:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Title");
alert.setMessage("Message");
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText();
// Do something with value!
//This is where you would put your make directory code
File photos = new File(getFilesDir(),value);
photos.mkdir();
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.show();
代码示例修改自
通常,在尝试创建新目录之前,最好先检查目录是否已经存在。为此,请替换您的创建目录代码
String value = "directory to create"
File photos = new File(getFilesDir(),value);
if(!photos.exists())
{
if(photos.mkdir())
{
//directory is created;
}
}
创建文件夹后如何刷新网格?网格是什么意思?GridView有一个方法。这将导致重建和重画所有视图。