skip to Main Content

I tried this but getting error because the function myListener should return something.

what I want to do is to get the seek bar value each time I’m changing it’s value at runtime and assign the value to another variable name counter.

class MainActivity : AppCompatActivity() {
    val seek = findViewById<SeekBar>(R.id.seekBar)
    var flashLightStatus: Boolean = false
    val counter = 0;



    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        seek.setOnSeekBarChangeListener(myListener())

        startFlashLight()
    }

    private fun myListener(): SeekBar.OnSeekBarChangeListener? {

    }

2

Answers


  1. You have to extend the function onProgressChanged

    
    seek.setOnSeekBarChangeListener(
        object : SeekBar.OnSeekBarChangeListener {
            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
                // Log.d("seekbar", "Your Progress: ${seekBar?.progress}"   
            }
    
            override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
            override fun onStopTrackingTouch(seekBar: SeekBar?) = Unit
        },
    )
    
    Login or Signup to reply.
  2. you can use this code and listen value change runtime

         seekBarView.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
                override fun onStopTrackingTouch(seekBar: SeekBar) {
                    Log.i(TAG, "onStopTrackingTouch: ")
                }
    
                override fun onStartTrackingTouch(seekBar: SeekBar) {
    
                }
    
               
                override fun onProgressChanged(
                    seekBar: SeekBar, progress: Int,
                    fromUser: Boolean
                ) 
                      // here 
    
            })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search