Time Keeps Flowing Like a River

If you want to display the time, rather than have users enter the time, you may wish to use the DigitalClock or AnalogClock widgets. These are extremely easy to use, as they automatically update with the passage of time. All you need to do is put them in your layout and let them do their thing.

For example, from the Fancy/Clocks sample application, here is an XML layout containing both DigitalClock and AnalogClock:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout width="fill parent"

android:layout height="fill parent" >

<AnalogClock android:id="@+id/analog" android:layout width="fill parent" android:layout height="wrap content" android:layout centerHorizontal="true" android:layout alignParentTop="true" />

<DigitalClock android:id="@+id/digital" android:layout width="wrap content" android:layout height="wrap content" android:layout centerHorizontal="true" android:layout below="@id/analog" />

</RelativeLayout>

Without any Java code other than the generated stub, we can build this project (see Figure 10-4).

Figure 10-4. The ClocksDemo sample application
0 0

Post a comment