Analog and Digital clock in Android with Example
In Android, Simple and computerized tickers are utilized to indicate time in android application.
The AnalogClock is a two-gave clock, one is hour marker and the another is minute pointer. The DigitalClock is resemble your typical computerized which show hours, watch available, minutes and seconds in advanced configuration.
Both AnalogClock and DigitalClock Can't alter the time, in the event that you need to change the time, utilize "TimePicker."
Example,
We should get begin by making a project in Eclipse IDE.
- Make another venture in Shroud by exploring to File⇒ New Android ⇒ Application Project and fill required points of interest. (I kept my fundamental movement name as MainActivity.java)
- Make a format petition for MainActivtiy.java under res ⇒ layout folder. I named the format record as activity_main.xml. In this design i had taken one Simple and one Computerized Clock.
<RelativeLayout xmlns:androclass=”http://schemas.android.com/apk/res/android”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
tools:context=”.MainActivity” >
<AnalogClock
android:id=”@+id/analogClock1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentTop=”true”
android:layout_centerHorizontal=”true”
android:layout_marginTop=”22dp” />
<DigitalClock
android:id=”@+id/digitalClock1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_below=”@+id/analogClock1″
android:layout_centerHorizontal=”true”
android:layout_marginTop=”81dp”
android:text=”DigitalClock” />
MainActivity.java
package com.example.analogdigital;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Output
Recommended Reading
Android Menu Tutorials
Skills and Responsibilities to be an Android Developer
Android Alert Dialog Example code
Tagged with : Android Analog clock coding | Android Digital clock coding | Android Tutorials | Interview Preparation Topics
Comments
Post a Comment