Android NotificationManager/NotificationHelper不更新百分比值
所以我有一个下载东西的课程。。。我正在基于实现NotificationHelperAndroid NotificationManager/NotificationHelper不更新百分比值,android,android-notifications,Android,Android Notifications,所以我有一个下载东西的课程。。。我正在基于实现NotificationHelper 私有类DatabaseStorageTask扩展了AsyncTask{ 受保护的字符串doInBackground(字符串…参数){ 对于(int i=0;i,当 protected String doInBackground(String... params) { while(downloadFileCount<100){ //try while instead of for-loop
私有类DatabaseStorageTask扩展了AsyncTask{
受保护的字符串doInBackground(字符串…参数){
对于(int i=0;i,当
protected String doInBackground(String... params) {
while(downloadFileCount<100){ //try while instead of for-loop
downloadFileCount++;
publishProgress(downloadFileCount); //only count downloadFileCount
}
}
受保护的字符串doInBackground(字符串…参数){
while(downloadFileCount答案在于使用float而不是int值来获取百分比
例如,20分之5=25%
5/20=0.25
当使用int=0时
int*100=0
使用float=0.25时
float*100=25请仔细查看我的括号…?(int)((downloadFileCount/totalDownloadFileCount)*100)在转换为int之前,我先进行100的乘法运算。这难道不能防止这种情况发生吗?请检查下面的示例:呃,谢谢您的尝试,但这完全不是我想要的……哈哈。我需要显示百分比。:)好的,对不起,现在无法测试。当我在家的时候,如果你在那之前没有找到解决方案,我会尝试一些东西……我做了一个计算日志,它是正确的。但不知怎么的,它没有发布,我不知道为什么会发生这种情况。
protected String doInBackground(String... params) {
while(downloadFileCount<100){ //try while instead of for-loop
downloadFileCount++;
publishProgress(downloadFileCount); //only count downloadFileCount
}
}