Skip to content

Conversation

@yeran27
Copy link

@yeran27 yeran27 commented Nov 24, 2025

No description provided.

Copy link

@kongwoojin kongwoojin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +22 to +27
var time = 0
var isRunning = false
var lapList = mutableListOf<String>()
var timerJob: Job? = null
var timerTask: Timer? = null
var lapAdapter = LapAdapter(lapList)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private 처리를 해도 좋을 것 같아요

recyclerView.adapter = lapAdapter
textViewTime.text = "00:00:00"

fun formatTime(millis: Int): String {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확장함수를 사용헀다면 더 좋을 것 같아요

val minutes = ((millis % 3600000) / 60000)
val seconds = ((millis % 60000) / 1000)
val ms = ((millis % 1000) / 10)
return String.format(Locale.US, "%02d:%02d:%02d", minutes, seconds, ms)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locale이 US인 이유가 있나요?

isRunning = true
timerJob = lifecycleScope.launch {
while (isRunning) {
delay(10)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coroutine에서 delay를 10ms만큼 준다고 실제 10ms만큼만 delay가 생기지 않습니다.
예를 들어, delay(1000)에 대해 전후에 System.currentTimeMillis()를 로그로 찍어보면, 실제로 1000ms만큼 차이가 나는 것이 아니라 오차가 발생하는 것을 확인할 수 있습니다.
왜 이런 현상이 발생하는지도 알아보시면 좋을 것 같아요.


buttonLap.setOnClickListener{
val currentTime = textViewTime.text.toString()
lapList.add(0, currentTime)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0번 인덱스에 추가하는 방법도 좋은 방법이지만, recyclerview 자체를 반대로 뒤집을 수도 있어요

Copy link
Collaborator

@KYM-P KYM-P left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

뭐지 너무 잘하셨습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants