반응형
[Gradle 설정]
1
|
id 'kotlin-android-extensions'
|
cs |
<MainActivity>
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
40
41
42
43
44
45
46
47
48
49
50
|
package com.cookandroid.project6_1
import android.graphics.Color
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
title = "시간 예약(수정)"
radioG.visibility = View.INVISIBLE
timePicker1.visibility = View.INVISIBLE
datePicker1.visibility = View.INVISIBLE
rdoCal.setOnClickListener {
datePicker1.visibility = View.VISIBLE
timePicker1.visibility = View.INVISIBLE
}
rdoTime.setOnClickListener {
datePicker1.visibility = View.INVISIBLE
timePicker1.visibility = View.VISIBLE
}
chronometer1.setOnClickListener {
chronometer1.start()
chronometer1.setTextColor(Color.RED)
radioG.visibility = View.VISIBLE
}
tvYear.setOnLongClickListener {
chronometer1.stop()
radioG.visibility = View.INVISIBLE
radioG.clearCheck()
timePicker1.visibility = View.INVISIBLE
datePicker1.visibility = View.INVISIBLE
chronometer1.setTextColor(Color.BLUE)
tvYear.text = datePicker1.year.toString()
tvMonth.text = datePicker1.month.toString()
tvDay.text = datePicker1.dayOfMonth.toString()
tvHour.text = timePicker1.currentHour.toString()
tvMinute.text = timePicker1.currentMinute.toString()
true
}
}
}
|
cs |
<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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Chronometer
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:format="예약에 걸린 시간 %s"
android:gravity="center"
android:textSize="30dp"
android:textColor="#0000FF"
android:id="@+id/chronometer1"/>
<RadioGroup
android:id="@+id/radioG"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:checked="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="날짜 설정(캘린더뷰)"
android:id="@+id/rdoCal"/>
<RadioButton
android:checked="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="시간 설정"
android:id="@+id/rdoTime"/>
</RadioGroup>
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<DatePicker
android:datePickerMode="spinner"
android:id="@+id/datePicker1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:timePickerMode="spinner"/>
</FrameLayout>
</LinearLayout>
<LinearLayout
android:background="#CCCCCC"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0000"
android:id="@+id/tvYear"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="년"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:id="@+id/tvMonth"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="월"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:id="@+id/tvDay"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="일"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:id="@+id/tvHour"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="시"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00"
android:id="@+id/tvMinute"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="분 예약됨"/>
</LinearLayout>
</LinearLayout>
|
cs |
반응형
'안드로이드 프로그래밍 > 코틀린' 카테고리의 다른 글
[코틀린을 활용한 안드로이드 프로그래밍] 6장 직접 풀어보기 6-3 (0) | 2022.05.25 |
---|---|
[코틀린을 활용한 안드로이드 프로그래밍] 6장 직접 풀어보기 6-2 (0) | 2022.05.22 |
[코틀린을 활용한 안드로이드 프로그래밍] 7장 직접 풀어보기 7-3 (0) | 2022.04.22 |
[코틀린을 활용한 안드로이드 프로그래밍] 10장 연습문제 5번 (0) | 2022.04.15 |
[코틀린을 활용한 안드로이드 프로그래밍] 10장 직접 풀어보기 10-3 (0) | 2022.04.15 |