Saturday, 8 March 2014

How to Implement AnalogClock Functionality in Android Application

This blog explain that how to create and implement AnalogClock functionality in android application.
In xml editor no need to write code manually you have to drag from palette Date & Time column of graphical view of xml editor.


main.xml


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:text="Analog Clock"
        android:textColor="#336633"
        android:textSize="20sp"
        android:textStyle="bold" />

<!--In xml editor no need to write code manually you have to drag from palette Date & Time column of graphical view of xml editor-->

    <AnalogClock
        android:id="@+id/analogClock1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
       android:background="#339966"
        android:layout_marginTop="80dp" />

</LinearLayout>

AnalogClockActivity.java




package com.rakesh.tiwari.analogclock;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AnalogClock;
import android.widget.Toast;

public class AnalogClockActivity extends Activity {
AnalogClock aClock;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
aClock = (AnalogClock) findViewById(R.id.analogClock1);
aClock.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),
"This is static code of Analog Clock",
Toast.LENGTH_LONG).show();
}
});
}

}


AndroidManifesr.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.rakesh.tiwari.analogclock"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.rakesh.tiwari.analogclock.AnalogClockActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


AnalogClock

AnalogClock Functionality



No comments:

Post a Comment