info@thistimebd.com

Sunday 24th of November 06:22:13am

Clock android app source code

package com.thistimebd.web.clock;


import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.AnalogClock;

import android.widget.TextClock;

import android.widget.Toast;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private TextClock textClock;

    private AnalogClock analogClock;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);


        textClock=(TextClock) findViewById(R.id.textClockId);

        analogClock=(AnalogClock) findViewById(R.id.analogClockId);


        analogClock.setOnClickListener(this);

        textClock.setOnClickListener(this);

    }


    @Override

    public void onClick(View v) {

        if(v.getId()==R.id.analogClockId){

            Toast.makeText(MainActivity.this,"Analog clock",Toast.LENGTH_SHORT).show();



        } if(v.getId()==R.id.textClockId){

            Toast.makeText(MainActivity.this,"Text clock",Toast.LENGTH_SHORT).show();



        }


    }

}


activity_main.xml


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical"

    android:padding="10dp"

    android:gravity="center"

    tools:context="com.thistimebd.web.clock.MainActivity">


   <AnalogClock

       android:id="@+id/analogClockId"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:layout_marginBottom="20dp"

       android:background="#63e1ac"



       />


  <TextClock

      android:id="@+id/textClockId"

      android:layout_width="wrap_content"

      android:layout_height="wrap_content"


      />


</LinearLayout>