Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 根据从不同类获得的值更新进度条_Java_Android_Android Progressbar - Fatal编程技术网

Java 根据从不同类获得的值更新进度条

Java 根据从不同类获得的值更新进度条,java,android,android-progressbar,Java,Android,Android Progressbar,我必须执行一个活动,在该活动中,我必须使用从不同类获取的值更新进度条的进度 在下载类中,我使用此函数计算进度 public void publishDownloadProgress(long lengthoffile, long bytesDownloaded){ mFileLength = lengthoffile; totalBytesDownloaded = bytesDownloaded; mProgress = ((totalBytesD

我必须执行一个
活动
,在该活动中,我必须使用从不同类获取的值更新
进度条
的进度

在下载类中,我使用此函数计算进度

public void publishDownloadProgress(long lengthoffile, long bytesDownloaded){
        mFileLength = lengthoffile;
        totalBytesDownloaded = bytesDownloaded;
        mProgress = ((totalBytesDownloaded*100)/mFileLength);    
    }
这是为了取得进展

public long getDownloadProgress(){
       return mProgress;
   }
但是当我使用
getDownloadProgress()
;在我的
活动中
,我只得到
0
,这是可以理解的,因为它只得到一次


但是我喜欢的是一系列连续的进度值,我想使用这些值更新我的
ProgressBar
,怎么做?

你应该多次调用getDownloadProgress()

并设置两次通话之间的时间间隔

因为第一次进度可能为零,所以您将获得零。 等待一段时间4ex线程睡眠(50000)


然后再次调用getDownloadProgress()您将获得更新的值

您使用的是异步任务还是处理程序?