Search code examples
androidandroid-seekbar

Custom Seekbar class implenting OnSeekBarChangeListener, onProgressChanged never called


I have a custom Seekbar class that has implemented OnSeekBarChangeListener, but the method onProgressChanged is never called and I am unsure why.

public class SeekbarSphereNodeRotator extends AppCompatSeekBar implements AppCompatSeekBar.OnSeekBarChangeListener {

    private static final String TAG = "SeekbarSphereNodeRotato";

   
    public SeekbarSphereNodeRotator(Context context) {
        super(context);
        //Gets called
        Log.d(TAG, "SeekbarSphereNodeRotator: " + mCurrentRotatedAngle);
    }

    public SeekbarSphereNodeRotator(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SeekbarSphereNodeRotator(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

        //Never called
        Log.d(TAG, "onProgressChanged: " + progress);
        
        
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }
}

The constructor is called, but the method onProgressChanged never is when I'm moving the seekbar thumb. What am I doing incorrectly?

mSeekbarImageRotater = new SeekbarSphereNodeRotator(MainActivity.this);

Edit:

I've tried adding setOnSeekBarChangeListener(this); in the constructor but that doesn't work either.


Solution

  • I had to set

    setOnSeekBarChangeListener(this);

    in

    public SeekbarSphereNodeRotator(Context context, AttributeSet attrs) {
       uper(context, attrs);
    }
    

    for the listener to work.