Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

android seekBar in kotlin cant create setOnSeekBarChangeListener

hey so I’m trying to make a simple seekbar but I’m facing some weird problems.
I programmed an app in kotlin about a year ago and it was different from what I’m experiencing now. first of all, why can I only initialize with lateinit? and then I can only access variables inside onCreate? anyway i was trying to make a seekbar but for some reason
kotlin does not recognize it like it dosent understand what I’m trying to do

the code:

class Generator : AppCompatActivity() {


lateinit var username: EditText
lateinit var app: EditText
lateinit var password: TextView

lateinit var caps: Switch
lateinit var numbers: Switch
lateinit var symbols: Switch

lateinit var seekbarvalue: TextView
lateinit var length: SeekBar

lateinit var generate: Button
lateinit var copy: Button
lateinit var save: Button
override fun onCreate(savedInstanceState: Bundle?) {

    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_generator)

    username = findViewById<EditText>(R.id.username)
    app = findViewById<EditText>(R.id.app)
    password = findViewById<TextView>(R.id.password)

    caps = findViewById<Switch>(R.id.caps)
    numbers = findViewById<Switch>(R.id.numbers)
    symbols = findViewById<Switch>(R.id.symbols)

    seekbarvalue = findViewById<TextView>(R.id.seekbarvalue)
    length = findViewById<SeekBar>(R.id.length)

    generate = findViewById<Button>(R.id.generate)
    copy = findViewById<Button>(R.id.copy)
    save = findViewById<Button>(R.id.save)

    length.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener){
        override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {

        }

    }
}

}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

 length.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
        override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {

        }

        override fun onStartTrackingTouch(p0: SeekBar?) {
            TODO("Not yet implemented")
        }

        override fun onStopTrackingTouch(p0: SeekBar?) {
            TODO("Not yet implemented")
        }

    })
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading