Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Progress bar pass float argument

Tags:

android

I tried to build a progress bar in android, as you know progress bar get int for progress, but I need to pass float to progress bar, what can I do?

private Runnable myThread = new Runnable(){  
    @Override
    public void run() {
                mypb = mypb + 100 / time;
                pb.setProgress(mypb);
    }
};
like image 310
Amir Sadegh Avatar asked Aug 12 '13 16:08

Amir Sadegh


2 Answers

You probably have it solved by now, but my workaround to this is multiplying by 10 or 100, depending on the number of decimals.

If your value is, 30.59 and your max is 100, then just multiply both values by 100. Which will give you 3059 and 10000.

like image 158
Leandro Temperoni Avatar answered Oct 07 '22 21:10

Leandro Temperoni


setProgress() doesn't have float argument. So you can not set float value.

but you can cast your float value to int by-

 pb.setProgress((int)mypb);
like image 35
T_V Avatar answered Oct 07 '22 21:10

T_V