Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom ProgressBar won't update. (AsyncTask + 9patch)
    primarykey
    data
    text
    <p>Firs of all thanks for reading this. I'm having trouble updating the progress from my custom ProgressBar through an AsyncTask inner class. I'm using 9patch for the background and progress drawables. It just don't update. It stays there all filled like it was in the maxed value, I'm using the onProgressUpdate() to call the invalidate() and update the UI thread.</p> <p>Here's what it looks like now, it goes visible and just stays there all filled up: <a href="http://imageshack.us/photo/my-images/651/mobicashprogressbar.png/" rel="nofollow">http://imageshack.us/photo/my-images/651/mobicashprogressbar.png/</a></p> <ul> <li>The progressbar should only be visible after the user concludes the form.</li> <li>There's another inner AsyncTask handling the send SMS button that connects with an Web Service.</li> </ul> <p><strong>HERES THE CODE:</strong></p> <pre><code>public void setTimerProgress(int progress){ progressBar.setProgress(progress); } public void updateProgress(){ progressBar.invalidate(); } public void showProgress(){ progressBar.setVisibility(View.VISIBLE); } //Classe auxiliar para controle da progress bar private class TimerProgress extends AsyncTask&lt;Void, Void, Void&gt;{ private int start; private final int OTP_TIMEOUT = 900000; @Override protected void onPreExecute() { super.onPreExecute(); showProgress(); start = (int) System.currentTimeMillis(); } @Override protected Void doInBackground(Void... param) { int timer = (int) System.currentTimeMillis() - start; while (timer &lt;= OTP_TIMEOUT){ setTimerProgress(timer); timer = (int) System.currentTimeMillis() - start; publishProgress(); } return null; } @Override protected void onProgressUpdate(Void... values) { super.onProgressUpdate(values); updateProgress(); } } </code></pre> <p><strong>HERE'S XML:</strong></p> <pre><code> &lt;ProgressBar style="@android:style/Widget.ProgressBar.Horizontal" android:layout_gravity="center_horizontal" android:visibility="invisible" android:id="@+id/progress_bar_timer" android:max="900000" android:progress="3000" android:progressDrawable="@drawable/progress_bar" android:background="@drawable/progress_background" android:layout_width="fill_parent" android:layout_height="25dip" android:layout_marginRight="73sp" android:layout_marginLeft="70sp"&gt; &lt;/ProgressBar&gt; </code></pre> <p><strong>HERE'S ONE PLACE WHERE I CALL IT</strong></p> <pre><code>@Override public void onClick(View v) { if (v.getId() == R.id.refresh_otp) { saveParametersForOTP(); if (edtIniPin.getText().length() == pinLengthInt) { try { disableEditText(edtIniPin); disableEditText(edtValue); edtOTP.setText(Facade.getInstance().nextOTP(Facade.getInstance().getPin(), Facade.getInstance().getValue())); //Inicia o timer da progressbar new TimerProgress().execute(); </code></pre> <p>Help? :D</p> <p><strong>UPDATE:</strong></p> <p>For test purpuses I've set the OTP_TIMEOUT to 50000, made the following changes to the code and removed the 9patch drawables properties so it would use the native drawables for the bar. It works, however, when I use the images to customize the bar it appears the same old problem is happening. It is static, all filled up like before.</p> <pre><code> private final int OTP_TIMEOUT = 50000; @Override protected void onPreExecute() { super.onPreExecute(); Log.i("PROGRESS", "Chegou no PreExecute!"); showProgress(); ENABLE_REFRESH = false; start = (int) System.currentTimeMillis(); } @Override protected Void doInBackground(Void... param) { int timer = (int) System.currentTimeMillis() - start; while (timer &lt;= OTP_TIMEOUT){ Log.i("PROGRESS", "Chegou no while!"); setTimerProgress((int)timer); timer = (int) System.currentTimeMillis() - start; publishProgress(); if (timer &gt;= OTP_TIMEOUT) { ENABLE_REFRESH = true; } } return null; } @Override protected void onProgressUpdate(Void... values) { super.onProgressUpdate(values); Log.i("PROGRESS", "Chegou no Progress Update!"); updateProgress(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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