简体   繁体   English

我正在使用Android重命名应用程序

[英]I'm making a renaming application in Android

Andorid 安多里德

I want to show progressdialog while doing renaming task. 我想在执行重命名任务时显示进度对话框。 The dialog should appear after clicking rename button. 单击重命名按钮后,将出现该对话框。 However, the progress dialog appears after renaming function(loop) is ended. 但是,重命名功能(循环)结束后,将显示进度对话框。 Here's my code 这是我的代码

public void onRenameClicked(View v){
    ProgressTask task = new ProgressTask();
    task.execute();
    for(int i = 0; i < num_of_files; i++){
            rename(file[i]);
    }
}

and Here's innerclass to show dialog 这是内部类以显示对话框

class ProgressTask extends AsyncTask<Integer, Void, Void>{
    ProgressDialog pd = new ProgressDialog(MainActivity.this);
    @Override
    protected Void doInBackground(Integer... i) {
        for(int j = 0; j < item.size(); j++) {
            pd.setProgress(j);
            pd.setMessage((j) + "/" + item.size());
        }
        return null;
    }
    @Override
    protected void onPreExecute() {
        pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        pd.setTitle("변경중");
        pd.setMax(item.size());
        pd.show();
    }
}

You have to use 你必须用

@Override
protected void onProgressUpdate(Integer... values) {
       super.onProgressUpdate(values);
       pd.setProgress(values[0]);
       pd.setMessage((values[0]) + "/" + values[1]);
}

and

publishProgress(j, item.size());

in the doInBackground() . doInBackground() These modifications are required because the setProgress and setMessage must be executed in the UI thread not in the background one. 这些修改是必需的,因为setProgresssetMessage必须在UI线程中而不是在后台线程中执行。

You do realize that you are calling your async task, with no data.. therfore its finishing quickly. 您确实意识到您正在调用异步任务,而没有数据..因此它很快完成。 You should probably pass in the list of files into the AsyncTask via arguments and then process those calls accordingly for each file INSIDE the AsyncTask and update the progress of the AsyncTask as you finish renaming files. 你或许应该在传递通过参数文件到的AsyncTask的列表,然后相应地处理这些电话为每个文件里面的AsyncTask和更新的AsyncTask的进度完成重命名文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试获取网站的内容并使其显示在android应用中 - I'm trying to fetch the content of website and making it to display in the android app 我正在用自定义视图在android中折叠工具栏。 - I'm making a collapsing toolbar in android with custom view. 在“应用程序管理器”选项卡中重命名Android App - Android App renaming in the application manager tab 重命名已发布的android应用程序有什么含义? - Are there any implications of renaming a published android application? Android:制作全屏应用程序 - Android: making a fullscreen application 重命名包和应用程序 ID Android 后是否需要更改 keyStore jks 文件 - Do i need to change keyStore jks file after renaming package and application id Android 当我在Android Studio中测试应用程序时,出现此错误: - When i'm testing the application in Android Studio i get this error: 重命名应用 - Renaming application 我正在做一个简单的清单应用程序。我能够将数据保存到文件中,但是当我关闭应用程序并重新打开时,我正在丢失数据 - I'm making a simple to do list application.I am able to save the data to file but when I close the application and reopen i'm loosing the data 我正在为 IOS 和 android 移动应用程序创建测试用例脚本 - I'm Creating test cases script for IOS and android mobile application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM