본문 바로가기
안드로이드

[Android] Clock

by 엘딘 2022. 3. 28.
activity_main.xml

TimePicker 입력

<TimePicker
	...
	// timePickerMode: clock, spinner모드 
	android:timePickerMode="clock"/>

 

 

MainActivity
class MainActivity : AppCompatActivity(), TimePicker.OnTimeChangedListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        var cal = Calendar.getInstance()
        val hour = cal.get(Calendar.HOUR_OF_DAY )
        val minute = cal.get(Calendar.MINUTE)

        val textView  = findViewById<TextView>(R.id.textView)
        val timePicker = findViewById<TimePicker>(R.id.timePicker)

        textView.text = "현재 설정된 시간 \n시 : 분 | $hour : $minute"

        timePicker.setOnTimeChangedListener(this)
    }

    override fun onTimeChanged(view:  TimePicker?, hourOfDay: Int, minute: Int) {
        val textView  = findViewById<TextView>(R.id.textView)

        textView.text = "현재 설정된 시간 \n시 : 분 | $hourOfDay : $minute"
    }
}

'안드로이드' 카테고리의 다른 글

[Android] Json  (0) 2022.03.31
[Android] File(추후 작성)  (0) 2022.03.31
[Android] DatePicker  (0) 2022.03.28
[Android] RatingBar  (0) 2022.03.28
[Android] seekbar  (0) 2022.03.28

댓글