Bài 20: DatePickerDialog và TimePickerDialog trong Android (P2)

Leave a Comment
- Nhìn vào giải thích ở  trên thì bạn phải hiểu được là khi muốn lấy Năm, Tháng, Ngày, giờ ,Phút , giây …. thì phải sài hằng số nào của Calendar. Ráng đọc và hiểu (Tôi nghĩ là phải hiểu)
- Thực hiện chương trình trên thì bạn sẽ có kết quả như bên dưới (tính tại thời điểm Tôi ví dụ):
Giờ định dạng 12 : 05:02:50 PM
Giờ định dạng 24 : 17:02:50
Bây giờ là: 12/04/2013 05:02:50 PM
Năm hiện tại : 2013
Tháng hiện tại : 4
Ngày hiện tại : 12
Lấy giờ định dạng 12 là : 5
Lấy giờ định dạng 24 là : 17
Phút hiện tại : 2
Giây hiện tại : 50
Mili giây hiện tại: 527
- 2) – Bạn đã biết cách sử dụng Date, Calendar, SimpleDateFormat, Giờ Ta bắt đầu làm ứng dụng:
- Tạo Android Project tên tùy thích và thiết kế giao diện giống như yêu cầu bên trên:
- Bạn xem Outline để dễ tưởng tượng ra giao diện, bạn thích làm kiểu nào là tùy bạn:
20_time_2- Còn đây là source XML (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/LinearLayout1"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical"
 tools:context=".MainActivity" >
<TextView
 android:id="@+id/textView1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="#008000"
 android:gravity="center"
 android:text="Quản lý công việc hàng tuần"
 android:textColor="#FFFFFF" />
<TableLayout
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:stretchColumns="*"
 >
<TableRow
 android:id="@+id/tableRow1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" >
<TextView
 android:id="@+id/textView2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Công việc:" />
<EditText
 android:id="@+id/editcongviec"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_span="2"
 android:ems="10" />
</TableRow>
<TableRow
 android:id="@+id/tableRow2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" >
<TextView
 android:id="@+id/textView3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Nội dung:" />
<EditText
 android:id="@+id/editnoidung"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_span="2"
 android:ems="10"
 android:inputType="textMultiLine" >
<requestFocus />
 </EditText>
</TableRow>
<TableRow
 android:id="@+id/tableRow3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" >
<TextView
 android:id="@+id/textView4"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Ngày HT:" />
<TextView
 android:id="@+id/txtdate"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="1/3/2013"
 android:textColor="#FF0000" />
<Button
 android:id="@+id/btndate"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Date" />
</TableRow>
<TableRow
 android:id="@+id/tableRow4"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" >
<TextView
 android:id="@+id/textView6"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Giờ HT:" />
<TextView
 android:id="@+id/txttime"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="8:30 AM"
 android:textColor="#FF0000" />
<Button
 android:id="@+id/btntime"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Time" />
</TableRow>
 </TableLayout>
<TextView
 android:id="@+id/textView9"
 android:layout_width="match_parent"
 android:layout_height="2dp"
 android:background="#E1E1E1" />
<Button
 android:id="@+id/btncongviec"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_gravity="center"
 android:text="Thêm CV" />
<TextView
 android:id="@+id/textView8"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="#008000"
 android:text="Danh sách công việc:"
 android:textColor="#FFFFFF" />
<ListView
 android:id="@+id/lvcongviec"
 android:layout_width="match_parent"
 android:layout_height="wrap_content" >
 </ListView>
</LinearLayout>
Xem tiếp P3....

0 nhận xét:

Đăng nhận xét