안드로이드 - 디지털 시계 샘플 안드로이드 이야기2013. 2. 15. 04:13
안드로이드 - 디지털 시계 샘플
출처:http://www.mkyong.com/android/android-analogclock-and-digitalclock-example/
In Android, the AnalogClock is a two-handed clock, one for hour indicator and the other for minute indicator. TheDigitalClock is look like your normal digital watch on hand, which display hours, minutes and seconds in digital format.
Both AnalogClock
and DigitalClock
are UNABLE to modify the time, if you want to change the time, use “TimePicker” instead.
P.S This project is developed in Eclipse 3.7, and tested with Android 2.3.3.
1. AnalogClock and DigitalClock
Open “res/layout/main.xml” file, add AnalogClock
and DigitalClock
in XML.
File : res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Analog Clock" android:textAppearance="?android:attr/textAppearanceLarge" /> <AnalogClock android:id="@+id/analogClock1" 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="Digital Clock" android:textAppearance="?android:attr/textAppearanceLarge" /> <DigitalClock android:id="@+id/digitalClock1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="DigitalClock" /> </LinearLayout>
2. Code Code
No idea what can i do with AnalogClock
or DigitalClock
.
File : MyAndroidAppActivity.java
package com.mkyong.android; import android.app.Activity; import android.os.Bundle; import android.widget.AnalogClock; import android.widget.DigitalClock; public class MyAndroidAppActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); AnalogClock ac = (AnalogClock) findViewById(R.id.analogClock1); //what can i do with AnalogClock? DigitalClock dc = (DigitalClock) findViewById(R.id.digitalClock1); //what can i do with DigitalClock also? for display only } }
3. Demo
Run the application.
1. This is how AnalogClock and DigitalClock look like :
Download Source Code
'안드로이드 이야기' 카테고리의 다른 글
안드로이드 - 사진촬영 후 사진과 포토앨범 가져오기 (0) | 2013.02.19 |
---|---|
안드로이드 - 동적으로 버튼 생성하기 (0) | 2013.02.18 |
안드로이드 - 타이머 샘플 (0) | 2013.02.15 |
안드로이드 - Click Listener 변화 (0) | 2013.02.14 |
안드로이드 - 가로, 세로 모드 전환 처리 (0) | 2013.02.14 |