Search code examples
javaandroidseekbar

Cannot resolve symbol 'OnSeekBarChangeListener'


I'm trying to create a SeekBar listener, but for some reason the following:

final SeekBar birthdaySlider = (SeekBar) findViewById(R.id.birthdaySlider);

birthdaySlider.setOnSeekBarChangeListener(new birthdaySlider.OnSeekBarChangeListener() {});

Returns the error:

Cannot resolve symbol 'OnSeekBarChangeListener'


Solution

  • Correct way to do :

    final SeekBar birthdaySlider = (SeekBar) findViewById(R.id.birthdaySlider);
    
    birthdaySlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    
            }
    
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
    
            }
    
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
    
            }
    });
    

    Tip: In Android Studio if you press ctrl+space keys, you will see autocomplete menu, which includes possible methods.