Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>I cannot show much of the code, but I do standard Fragment attachment and then create a thread in the fragment with a specific sleep period and then updating the seekbar progress on ui-thread.</p> </blockquote> <p>Try using a <code>Handler</code> to update the <code>ProgressBar</code>:</p> <p>Define the following global variables:</p> <pre><code>Handler updateHandler; // loop control variable boolean shouldStop; Runnable updateRunnable; </code></pre> <p>Initialize variables:</p> <pre><code>updateHandler = new Handler(); shouldStop = false; updateRunnable = new Runnable() { @Override public void run() { if (!shouldStop) { // Post this Runnable again with a delay of 1000 milliseconds updateHandler.postDelayed(this, 1000L); // Update ProgressBar updateCallback(Your_Progress_Value); } } }; // Start the update process updateHandler.post(updateRunnable); </code></pre> <p>And you do not need to specify the thread to run the update on in this case:</p> <pre><code>/* Called every 1 sec */ void updateCallback(final int progress) { if (seekBarView == null) { seekBarView = (SeekBar) view.findElementById(R.id.progressBar); } seekBarView.setProgress(...); } </code></pre> <p>The <code>boolean</code> variable <code>shouldStop</code> will be used when you need to end the update process. Set it to <code>true</code> and the updates will stop.</p> <p>Note: You have a <code>ProgressBar</code> widget in your layout and your code uses a <code>SeekBar</code>. Could you make that correction in your post? Another thing, there's no method with signature <code>findElementById(int)</code> in <code>View</code>. Is this your actual code?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload