Analog clock and Digital clock
The android.widget.AnalogClock and android.widget.DigitalClock classes gives the usefulness to show simple and computerized timekeepers.
Android simple and computerized timekeepers are utilized to demonstrate time in android application.
Android AnalogClock is the subclass of View class.
Android DigitalClock is the subclass of TextView class. Since Android API level 17, it is censured. You are prescribed to utilize TextClock Instead.
Note: Analog and Digital timekeepers can't be utilized to change the season of the gadget. To do as such, you have to utilize DatePicker and TimePicker.
In android, you have to drag simple and computerized timekeepers from the bed to show simple and advanced tickers. It speaks to the planning of the present gadget.
activity_main.xml
Now, drag the analog and digital clocks, now the xml file will look like this.
<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" />
RelativeLayout>
Activity class
We have not write any code here.
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;
}
}