Search code examples
androidseekbar

Android SeekBarListener in a different class


When a seekbar is changed. Where is the listener activated?

EX:

ClassA
{
    ClassB myClass = new ClassB(); 

}
ClassB
{
   SeekBar mySeekBar = new SeekBar;
}

If the seekBar is in classB. Can I have the listener in ClassA ? Or do I have to have it in ClassB and toss a flag back to ClassA?

My goal is to tell ClassA how much the progress is on ClassB's seekbar.


Solution

  • The listener can be anywhere you want. This is why you have a setOnSeekBarChangeListener() to register it. That class listening should extend SeekBar.OnSeekBarChangeListener, and pass it to setOnSeekBarChangeListener() for that given SeekBar.