Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created July 12, 2022 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeforfun-jp/de7e0c712560bd4be7931d344ebababb to your computer and use it in GitHub Desktop.
Save codeforfun-jp/de7e0c712560bd4be7931d344ebababb to your computer and use it in GitHub Desktop.
【Kotlin】How to Use SeekBar 5
package com.example.seekbarsample
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.SeekBar
import android.widget.TextView
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val textView = findViewById<TextView>(R.id.textView)
val seekbar = findViewById<SeekBar>(R.id.seekbar)
val button = findViewById<Button>(R.id.button)
// 初期値を表示
textView.text = "${seekbar.progress}"
// 「リセット」を押したら50にする
button.setOnClickListener {
seekbar.progress = 50
}
// SeekBarイベント
seekbar.setOnSeekBarChangeListener(
object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {
textView.text = "$p1"
}
override fun onStartTrackingTouch(p0: SeekBar?) {
}
override fun onStopTrackingTouch(p0: SeekBar?) {
}
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment