change Low/Medium/High color in Recycler view at runtime
I have a recycle view whose view gets updated in every 30 seconds. I am able to change the color on Indicator but speed view color is changed to another color.
I guess the issue is with the recycled views.
first time image : (this is what it looks when the view is created for the first time.)

But after the refresh or down in the list view I see this ;

I have checked the code
this.mediumSpeedColor = mediumSpeedColor;
if (!isAttachedToWindow())
return;
updateBackgroundBitmap();
invalidate();
I guess the recycled view is already attached to the window.
Please suggest what to do?
So you want to change indicator color or speedometer color? May you show me the code.
i want to change both of them. as in first image. but when i scroll down or the list refresh only the color of indicator changes not the color of speedometer
Try to call speedometer.invalidate() after you change the the bar color.
It's not working. It is showing random behavior for bar color. I guess this method needs to get called updateBackgroundBitmap(); from setHighSpeedColor() before invalidate.
That's weird! Give me xml tag for SpeedView and code where you change the color, i will try to fix it.
java code (adapter's onBindViewHolder) ` switch (state) {
case Running:
vehileViewHolder.statusColour.setBackground(mContext.getResources().getDrawable(R.drawable.state_green_circle));
vehileViewHolder.speedView.setLowSpeedColor(mContext.getResources().getColor(R.color.n_green_dot));
vehileViewHolder.speedView.setMediumSpeedColor(mContext.getResources().getColor(R.color.n_green_dot));
vehileViewHolder.speedView.setHighSpeedColor(mContext.getResources().getColor(R.color.n_green_dot));
vehileViewHolder.speedView.setIndicatorColor(mContext.getResources().getColor(R.color.n_green_dot));
vehileViewHolder.speedView.invalidate();
break;
case Overspeed:
vehileViewHolder.statusColour.setBackground(mContext.getResources().getDrawable(R.drawable.state_red_circle));
vehileViewHolder.speedView.setLowSpeedColor(mContext.getResources().getColor(R.color.n_red_dot));
vehileViewHolder.speedView.setMediumSpeedColor(mContext.getResources().getColor(R.color.n_red_dot));
vehileViewHolder.speedView.setHighSpeedColor(mContext.getResources().getColor(R.color.n_red_dot));
vehileViewHolder.speedView.setIndicatorColor(mContext.getResources().getColor(R.color.n_red_dot));
vehileViewHolder.speedView.invalidate();
break;
}`
XML ;
<com.github.anastr.speedviewlib.SpeedView android:id="@+id/speedView" android:layout_width="90dp" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_toLeftOf="@id/iv_blur_icon" android:paddingRight="10dp" app:sv_endDegree="360" app:sv_indicator="NeedleIndicator" app:sv_indicatorWidth="8dp" app:sv_lowSpeedColor="@color/four_f" app:sv_mediumSpeedColor="@color/four_f" app:sv_lowSpeedPercent="75" app:sv_maxSpeed="200" app:sv_mediumSpeedPercent="100" app:sv_minSpeed="0" app:sv_speedTextFormat="INTEGER" app:sv_speedTextPosition="CENTER" app:sv_speedTextSize="@dimen/home_list_item_content_text_size" app:sv_speedometerMode="TOP" app:sv_speedometerWidth="5dp" app:sv_startDegree="180" app:sv_trembleDegree="2" app:sv_unitTextSize="@dimen/home_list_item_address_bottom_margin" app:sv_withTremble="true" />
By when this will be fixed and released? I really need this.
I am so busy at this time, and there are too many issues need to handle...
I don't know when i will finish it up, but if you are in a hurry you can extenda SpeedView and override onAttachedToWindow() method like this:
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
updateBackgroundBitmap();
invalidate();
}
Don't change anything else. This resolve your issue until next version.
Thanks @anastr . It worked. One more thing is there any library like this in iOS?
unfortunately No, you have to look for other lib.
fixed in V 1.3.0.