[英]How to display Toast after done task?
I use this code to delete a file 我使用此代码删除文件
File dir = new File(Environment.getExternalStorageDirectory() + "/myapp/" + "/Media/");
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
new File(dir, children[i]).delete();
}
Toast.makeText(appActivity.this, "done", Toast.LENGTH_SHORT).show();
}
I want to show Toast "done" after deleting the file from folder and other Toast "No file" if there is o file in the folder. 如果文件夹中有o文件,我想在文件夹和其他Toast“No file”中删除文件后显示Toast“done”。
How can I do that? 我怎样才能做到这一点?
What you need is an if else statement, for more help on if else statements read the Android Developers documentation https://developer.android.com/reference/java/util/concurrent/locks/Condition.html 你需要的是if else语句,有关if else语句的更多帮助,请阅读Android开发人员文档https://developer.android.com/reference/java/util/concurrent/locks/Condition.html
Try this; 尝试这个;
File dir = new File(Environment.getExternalStorageDirectory() + "/myapp/" + "/Media/");
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
new File(dir, children[i]).delete();
}
Toast.makeText(appActivity.this, "done", Toast.LENGTH_SHORT).show();
else {
Toast.makeText(appActivity.this, "no file!", Toast.LENGTH_SHORT).show();
}
}
well i think this should work 我认为这应该有效
File dir = new File(Environment.getExternalStorageDirectory() + "/myapp/" + "/Media/");
if (dir.isDirectory()) {
String[] children = dir.list();
//if there are files to delete inside the folder
if(children.length>0){
Toast.makeText(appActivity.this, "done", Toast.LENGTH_SHORT).show();
}
//if there are no files inside the folder
else{
Toast.makeText(appActivity.this, "No files to delete", Toast.LENGTH_SHORT).show();
}
for (int i = 0; i < children.length; i++) {
new File(dir, children[i]).delete();
}
}
else{
Toast.makeText(appActivity.this, "No Such directory exists", Toast.LENGTH_SHORT).show();
}
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.