I have been stuck on this problem since a long time. I left it then came back to it but so far I haven't found a working solution. Problem is simple, I have a vertical seekbar and I want to update it programmatically without touching it, but it doesn't happen. This is my vertical seekbar code
public class VerticalSeekBar extends SeekBar {
public VerticalSeekBar(Context context) {
super(context);
}
public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public VerticalSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(h, w, oldh, oldw);
}
@Override
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}
protected void onDraw(Canvas c) {
c.rotate(-90);
c.translate(-getHeight(), 0);
super.onDraw(c);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isEnabled()) {
return false;
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
onSizeChanged(getWidth(), getHeight(), 0, 0);
break;
case MotionEvent.ACTION_CANCEL:
break;
}
return true;
}
}
This is how the seekbar is declared in the xml
<com.gnr.kumar.varun.songapp.views.VerticalSeekBar
android:id="@+id/slider_1"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:max="100"
android:padding="10dp"
android:progress="50"
android:progressBackgroundTint="#9cf2ec"
android:progressTint="#9cf2ec"
android:thumb="@drawable/thumb" />
I try to do things like
SeekBar sliders[] = new SeekBar[NUM_OF_SLIDERS];
sliders[0] = (SeekBar) findViewById(R.id.slider_1);
sliders[0].setProgress(100);
But it just changes the seekbar position to slightly more than 0 when in fact it should be at its maxima. No matter how big number I use instead of 100, it is the same. Can someone please help !! Thanks in advance !!!