레쭈고 코틀린

Kotlin 9차시

정땅미 2024. 10. 31. 10:52

오늘은 코틀린으로 무엇을 했냐 하면 바로... 

또 똑같은 클릭이벤트를 했어요! 그래도 어떤 새로운 걸 했냐고 하면 바로 시계를 만들어 봤어유 ㅎㅅㅎ

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
        <Chronometer
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/chronometer1"
            android:format="예약에 걸린 시간 %s"
            android:gravity="center"
            android:textSize="20dp" />
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/btnStart"
            android:text="예약시작" />
    </LinearLayout>
    <RadioGroup
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rdoCal"
            android:text="날짜 설정(캘린더 뷰)" />
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/rdoTime"
            android:text="시간 설정"/>
    </RadioGroup>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >


            <CalendarView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/calView1"/>
            <TimePicker
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/tiemPick1" />
        </FrameLayout>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="horizontal"
        android:background="#cccccc"
        android:layout_height="wrap_content">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btnEnd"
            android:background="#FFEB3B"
            android:text="예약완료" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tvResult"
            android:text="0000" />
        <TimePicker
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:timePickerMode="spinner" />
        <DatePicker
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:datePickerMode="spinner" />
    </LinearLayout>

 

이렇게 입력해 주면 시계의 종류가 엄청 많이 뜨거든요?

근데 디자인이 별로 안 예뻐서 꼭! 필요할 때가 아니면 많이 사용하지 않을 것 같아요 ㅋㅋㅋㅋㅋㅋ

Chronometer는 이러한 모양의 시계를 보여줍니다!

 

제가 다음 것들도 보여주려 했는데 코드를 이상하게 작성했는지 겹쳐져 보여서ㅠㅠ 속상하군요

 

그럼 다음으로... 코드 사이에 RadioButton 이 있는데 그걸 눌렀을 때, 서로 다른 페이지를 보여주는 것도 구현해 봣어용

setContentView(R.layout.activity_main2)
        this.setTitle("시간 예약")
        this.title = "시간 예약"

        var btnStart = findViewById<Button>(R.id.btnStart)
        var btnEnd = findViewById<Button>(R.id.btnEnd)
        var rdoCal = findViewById<RadioButton>(R.id.rdoCal)
        var rdoTime = findViewById<RadioButton>(R.id.rdoTime)
        var calView = findViewById<CalendarView>(R.id.calView1)
        var tPicker = findViewById<TimePicker>(R.id.tiemPick1)

        rdoCal.setOnClickListener {
            tPicker.visibility = View.INVISIBLE // 안 보이게
            calView.visibility = View.VISIBLE // 보이게
        }

        rdoTime.setOnClickListener {
            tPicker.visibility = View.VISIBLE // 안 보이게
            calView.visibility = View.INVISIBLE // 보이게
        }

 

우선 activity_main2 에서 만들어준 위젯들을 전부 변수로 지정해 줬어요!

그리고 지금 저희에게 필요한 것은 RadioButton 을 지정한 변수이기 때문에 거기서 setOnClickListener 로 이벤트를 줬어요!

rdoCal 을 눌렀을 때는 tPicker 을 숨기고, calView 를 보여줍니닷!

그리고 rdoTime 은 반대로 해주면 제가 원하는 대로 구현이 가능해요~

생각보다 예쁘게~ 구현되어서 다행이라구 생각했어요~

 

오늘도 유익한 내용을 배워서 또 쓰러 오겠습니당. ψ(`∇´)ψ

'레쭈고 코틀린' 카테고리의 다른 글

Kotlin 11차시  (2) 2024.11.26
Kotlin 10차시  (0) 2024.11.10
Kotlin 8차시  (3) 2024.10.23
Kotlin 7차시  (3) 2024.10.21
Kotlin 6차시  (3) 2024.09.27