I'm trying to do add a progressbar in code and make it determinate:
progressBar = new ProgressBar(getActivity());
progressBar.setLayoutParams(layoutParams);
parent.addView(progressBar, index);
progressBar.setId(id.list_item_secondary);
progressBar.setProgressDrawable(getResources().getDrawable(drawable.progress_horizontal));
progressBar.setIndeterminate(false);
progressBar.setMax(100);
After progressBar.setIndeterminate(false)
, isIndeterminate
is still true and the progress keeps shows the indeterminate circle.
How can I make it determinate?
From the ProgressBar source code here, the constructor you are calling is in line 237 which is calling the constructor in line 241 which in turn calls the constructor in line 245 with the style:
com.android.internal.R.attr.progressBarStyle
This style has the attribute android:indeterminateOnly set to true by default so your calls to setIndeterminate are ignored. See the function description at line 433.
I haven't done this but I assume that if you call the constructor in line 245 like this:
progressBar = new ProgressBar(getActivity(), null, <Your Style ID>);
passing as the third parameter a style definition with android:indeterminateOnly to false it should work. Based in the source code I assume that setIndeterminate is there only to enable it and not to disable it.
Hope this helps...
It doesn't look like you are setting the ProgressBar's style attribute. From the docs for setIndeterminate()
:
If this progress bar's style only supports indeterminate mode (such as the circular progress bars), then this will be ignored.
You should manually set the style e.g. via style="@android:style/Widget.ProgressBar.Horizontal"
. Simply changing the Drawable
isn't enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With