Javatpoint Logo

91-9990449935

 0120-4256464

Android Analog clock and Digital clock example

The android.widget.AnalogClock and android.widget.DigitalClock classes provides the functionality to display analog and digital clocks.

Android analog and digital clocks are used to show time in android application.

Android AnalogClock is the subclass of View class.

Android DigitalClock is the subclass of TextView class. Since Android API level 17, it is deprecated. You are recommended to use TextClock Instead.

Note: Analog and Digital clocks cannot be used to change the time of the device. To do so, you need to use DatePicker and TimePicker.

In android, you need to drag analog and digital clocks from the pallet to display analog and digital clocks. It represents the timing of the current device.

activity_main.xml

Now, drag the analog and digital clocks, now the xml file will look like this.

File: activity_main.xml

Activity class

We have not write any code here.

File: MainActivity.java


Output:

android analog and digital clocks example output 1