activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical"> <TextView android:id="@+id/progress" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="20dp" android:text="- -" android:textSize="24sp" /> <TextView android:id="@+id/seekbarStatus" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="20dp" android:text="- -" android:textSize="24sp" /> <SeekBar android:id="@+id/seekbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="15dp" /> </LinearLayout> </android.support.constraint.ConstraintLayout> |
MainActivity.kt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
package com.phaisarn.ktapplication import android.support.v7.app.AppCompatActivity import android.os.Bundle import android.widget.SeekBar import android.widget.TextView import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity(), SeekBar.OnSeekBarChangeListener { private var progressView: TextView? = null private var seekbarStatusView: TextView? = null private var seekbarView: SeekBar? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) progressView = this.progress seekbarStatusView = this.seekbarStatus seekbarView = this.seekbar seekbarView!!.setOnSeekBarChangeListener(this) } override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { progressView!!.text = progress.toString() seekbarStatusView!!.text = "Tracking Touch" } override fun onStartTrackingTouch(seekBar: SeekBar) { seekbarStatusView!!.text = "Started Tracking Touch" } override fun onStopTrackingTouch(seekBar: SeekBar) { seekbarStatusView!!.text = "Stopped Tracking Touch" } } |