I am appending progressbar in elements of a list and also dynamically updating that progressbar.
But the odd situation that i m facing is that..
When i have more than one element in my list and i change the color of progressbar by using Progressbar.setProgressDrwable(), all progressbars in the list are updated and their color is changed as desired.
But when I have only one single element in the list this method doesn’t work, All I can see the background of my progressbar not the color.
I have also created my XML file for progressbar’s background and color but than also its not working.
My XMl code for ProgressDrawable is
FirstColor.xml
<item android:id="@android:id/background">
<shape>
<corners android:radius="15dip" />
<gradient android:startColor="#A9A9A9" android:centerColor="#A9A9A9"
android:endColor="#A9A9A9" android:angle="90" />
<stroke android:width="5dp" android:color="#A9A9A9" />
</shape>
</item>
<item android:id="@android:id/progress">
<scale android:scaleGravity="left" android:scaleWidth="100%" >
<shape>
<corners android:radius="15dip" />
<gradient android:startColor="#ADFF2F" android:centerColor="#ADFF2F"
android:endColor="#ADFF2F" android:angle="90" />
<stroke android:width="5dp" android:color="#ADFF2F" />
</shape>
</scale>
</item>
SecondColor.xml
<item android:id="@android:id/background">
<shape>
<corners android:radius="15dip" />
<gradient android:startColor="#A9A9A9" android:centerColor="#A9A9A9"
android:endColor="#A9A9A9" android:angle="90" />
<stroke android:width="5dp" android:color="#A9A9A9" />
</shape>
</item>
<item android:id="@android:id/progress">
<scale android:scaleGravity="left" android:scaleWidth="100%" >
<shape>
<corners android:radius="15dip" />
<gradient android:startColor="#FFBF00" android:centerColor="#FFBF00"
android:endColor="#FFBF00" android:angle="90" />
<stroke android:width="5dp" android:color="#FFBF00" />
</shape>
</scale>
</item>
and the java code that i m using to change the color of progressbar is
progressbar1.setProgressDrawable(getResources().getDrawable(R.drawable.FirstColor));
progressbar1.setProgress(amntPercentage.intValue());
progressbar1.setProgressDrawable(getResources().getDrawable(R.drawable.SecondColor));
progressbar1.setProgress(amntPercentage.intValue());
If anyone out there can solve my problem it would be a great help..
Thanks in advance..
Before setting the new
progressDrawableand setting theprogressvalue, make sure that you have not setted theprogressvalueto ‘0’.This happens because in
style.xmlfor progressbar we define the xml fields only for start, middle and end; not for ‘0’.I setted the progressvalue to ‘1’ before changing the drawable and my project is working fine.