Open In App
Related Articles

Android | How to display Analog clock and Digital clock

Improve Article
Save Article
Like Article


Analog and digital clocks are used for display the time in android application.

  1. Analog clock: Analog clock is a subclass of View class. It represents a circular clock. Around the circle, numbers 1 to 12 appear to represent the hour and two hands are used to show instant of the time- shorter one for the hour and longer is for minutes.
  2. Digital clock: Digital clock is subclass of TextView Class and uses numbers to display the time in “HH:MM” format.

For Example

In this Article, a simple android application is built to display the Analog clock and Digital clock.

How to create a Android Analog clock and Digital clock?

This example will help to develop an Android App that displays an Analog clock and a Digital clock according to the example shown above:
Below are the steps for Creating the Analog and Digital clock Android Application:

  • Step1: Firstly create a new Android Application. This will create an XML file “activity_main.xml” and a Java File “MainActivity.Java”. Please refer the pre-requisites to learn more about this step.

  • Step2: Open “activity_main.xml” file and add following widgets in a Relative Layout:
    • An Analog clock
    • A Digital clock

    This will make the UI of the Application. There is no need for assignment of IDs as these widgets will display the time by themselves.

  • Step3: Leave the Java file as it is.
  • Step4: Now Run the app. Both clocks are displayed on the screen.

The complete code of and activity_main.xml of Analog Digital clock is given below:


<?xml version="1.0" encoding="utf-8"?>
       android:layout_height="wrap_content" />
        android:layout_height="wrap_content" />

package org.geeksforgeeks.navedmalik.analogdigital;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState)


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 19 Feb, 2021
Like Article
Save Article
Similar Reads
Complete Tutorials