0

I'm a "fresh" Android developer and i tried the horizontal ProgressBar. I have a little issue with it, progress stops in the middle and does not continue till the end of the bar.

Can you help me please?

this is my code

    progress=0;
mProgress = (ProgressBar) findViewById(R.id.progressBar1);   
mProgress.setMax(200);


// Start lengthy operation in a background thread         
new Thread(new Runnable() 
{             
    public void run() 
    {                 

        while (mProgressStatus < 100) 
        {                     

            mProgressStatus = doWork();                     
            // Update the progress bar                     
            mHandler.post(new Runnable() 
            {                         
                public void run() 
                {                             
                    mProgress.incrementProgressBy(20);
                    mProgress.setProgress(mProgressStatus);                         
                }                     
            });                 
        }

        // Cache la progressBar 
        mHandler.post(new Runnable() 
        {

            @Override
            public void run() 
            {
                mProgress.setVisibility(4);
    }
    });

    }
    //---------------------------------Work to do-----------------------
    private int doWork()
    {
        try{
            Thread.sleep(50);//5 secondes
        }catch(InterruptedException e)
        {
            e.printStackTrace();
        }
        return ++progress;
    }
    //------------------------------------------------------------------

}).start();
    }

1 Answers1

0

You set the progress bar maximum value to 200:

mProgress.setMax(200);

and later in code you stop when it raises to 100 (half filled). Either set the maximum to 100 or keep running till 200.

Ivan Shagin
  • 423
  • 3
  • 7