two Bars which shows the progress of a game. If the user get points or time is up etc the progressBars should be updated:
private TextView tv;
private ProgressBar levelHoldBar;
private ProgressBar levelUpBar;
//...
private void updateViews() {
// ...
levelHoldBar.setMax(currentLevel.getThreshold());
levelHoldBar.setProgress(currentPoints > currentLevel.getThreshold() ? currentLevel.getThreshold() : currentPoints);
levelUpBar.setMax(nextLevel.getThreshold());
levelUpBar.setProgress(currentPoints > nextLevel.getThreshold() ? nextLevel.getThreshold() : currentPoints);
tv.setText(currentPoints+"/"+currentLevel.getThreshold());
Log.d(TAG, "hold prog/max "+levelHoldBar.getProgress()+"/"+levelHoldBar.getMax());
Log.d(TAG, "up prog/max "+levelUpBar.getProgress()+"/"+levelUpBar.getMax());
}
ie. Outputs:
12-03 17:48:33.918: DEBUG/MainActivity(6829): hold prog/max 20/20
12-03 17:48:33.918: DEBUG/MainActivity(6829): up prog/max 20/50
The Log.d(...) in the end shows ALWAYS the correct values, but SOMETIMES the visual bars of the progressBars do not show the correct progesses. They show progresses that had been set previously even if the getters for "max" and "progress" return correct values (in the example the bar shows about 20% (instead of 100%) for the levelHoldBar and about 2% (instead of 40%) for the levelUp-bar). I cannot figure out, why the log-output is correct but the drawables are wrong!? The TextView (tv) is updated correctly! Whats going on here? How can I fix that?
This worked for me...
OneFragmen.java
I have tried in many ways by calling setProgress in Thread, runOnUiThread, Handler, Runnable. All of them dont work.
So finally, set value of dialog.setIndeterminate(false); will work.
Once you set dialog.setIndeterminate(true); the progress WONT UPDATE AT ALL.