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 it put them in your layout and let them do their thing.

For example, from the 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 and get the following activity:

If you need to be doing something for a long period of time, you owe it to your users to do two things:

• Use a background thread, which will be covered in a later chapter

• Keep them apprised of your progress, lest they think your activity has wandered away and will never come back

The typical approach to keeping users informed of progress is some form of progress bar or "throbber" (think the animated graphic towards the upper-

Figure 28. The ClocksDemo sample application
Self Publishing

Self Publishing

Have you always wanted to write your own book and get it published? Discover How to Write, Print Sell Your Own Book! Have you always wanted to write your own book and get it published? If you have written a book or even if you have a yen to be a writer, you are probably already aware of the competition in the writing field.

Get My Free Ebook


Post a comment