Software Development Exam  >  Software Development Notes  >  How to display an Analog clock and a Digital clock

How to display an Analog clock and a Digital clock - Software Development PDF Download

Android | How to display Analog clock and Digital clock

Last Updated: 19 Feb, 2021

Pre-requisites:

  • Android App Development Fundamentals for Beginners
  • Guide to Install and Set up Android Studio
  • Android | Starting with first app/android project
  • Android | Running your first Android app

Analog and Digital Clocks Overview:

Analog and digital clocks are essential components used to display time in an Android application.

Analog Clock

Analog clock is a subclass of the View class. It visually represents time using a circular clock face. The clock features numbers 1 to 12 around the circle to denote hours. Additionally, it consists of two hands - a shorter one indicating the hour and a longer one for minutes.

Digital Clock

Digital clock, on the other hand, belongs to the TextView class. It utilizes numbers to exhibit time in the "HH:MM" format.

For Example

How to display an Analog clock and a Digital clock - Software Development

How to create an Android Analog clock and Digital clock?

This tutorial will guide you through developing an Android application that showcases both Analog and Digital clocks.

Steps to Create an Analog and Digital Clock Android Application:

  • Step 1: Initiate a new Android Application. This action generates an XML file named "activity_main.xml" and a Java File named "MainActivity.Java". Refer to the pre-requisites for a detailed understanding of this step.
  • Step 2: Access the "activity_main.xml" file and incorporate the following widgets within a Relative Layout:
    • An Analog clock
    • A Digital clock
    This setup forms the User Interface (UI) of the Application. No need to assign IDs as these widgets autonomously display the time.
  • Step 3: Keep the Java file unchanged.
  • Step 4: Execute the application. Subsequently, both clocks will be visible on the screen.

Creating an Analog and Digital Clock in Android Application

  • Step 1: Create a new Android Application. This step generates an XML file named "activity_main.xml" and a Java File named "MainActivity.Java". Refer to the prerequisites for more details.
  • Step 2: In the "activity_main.xml" file, include the following widgets in a Relative Layout: An Analog clock and a Digital clock. This configuration establishes the UI of the Application. There is no necessity to assign IDs as these widgets will autonomously display the time.
    • An Analog clock
    • A Digital clock
  • Step 3: Leave the Java file unaltered.
  • Step 4: Run the application. Subsequently, both clocks will be exhibited on the screen.

Code Snippet

The complete code of MainActivity.java and activity_main.xml for the Analog Digital clock is provided below:

  • activity_main.xml
  • MainActivity.java

Java Code Snippet

  • Package Declaration:
    • package org.geeksforgeeks.navedmalik.analogdigital;
  • Imports:
    • import android.support.v7.app.AppCompatActivity;
    • import android.os.Bundle;
  • Main Activity Class:
    • public class MainActivity extends AppCompatActivity {
  • onCreate Method:
    • @Override
    • protected void onCreate(Bundle savedInstanceState) {
    • super.onCreate(savedInstanceState);
    • setContentView(R.layout.activity_main);
    • }

Output:

How to display an Analog clock and a Digital clock - Software Development

Please Login to comment...

LoginLike
The document How to display an Analog clock and a Digital clock - Software Development is a part of Software Development category.
All you need of Software Development at this link: Software Development
Download as PDF

Top Courses for Software Development

Related Searches

pdf

,

Sample Paper

,

ppt

,

Viva Questions

,

Free

,

Semester Notes

,

mock tests for examination

,

Objective type Questions

,

video lectures

,

practice quizzes

,

MCQs

,

shortcuts and tricks

,

How to display an Analog clock and a Digital clock - Software Development

,

Previous Year Questions with Solutions

,

past year papers

,

study material

,

How to display an Analog clock and a Digital clock - Software Development

,

Extra Questions

,

Important questions

,

Summary

,

How to display an Analog clock and a Digital clock - Software Development

,

Exam

;