ChronoMeter

ChronoMeter

/res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<TextView android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:text="@string/hello" />
	<Chronometer android:id="@+id/Chronometer01"
		android:layout_width="wrap_content" android:layout_height="wrap_content"
		android:format="Timer: %s" />
	<DigitalClock android:id="@+id/DigitalClock01"
		android:layout_width="wrap_content" android:layout_height="wrap_content" />
	<AnalogClock android:id="@+id/AnalogClock01"
		android:layout_width="wrap_content" android:layout_height="wrap_content"
		android:dial="@drawable/icon" />
</LinearLayout>

Activity file

package com.androidwork.timecontroldemo;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Chronometer;

public class TimeControlDemoActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		final Chronometer timer = (Chronometer) findViewById(R.id.Chronometer01);
		// long base = timer.getBase();
		// Log.d(ViewsMenu.debugTag, “base = “+ base);
		// timer.setBase(0);
		timer.setBase(android.os.SystemClock.elapsedRealtime());
		timer.start();

	}
}

Output

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s