Analogclock And Digitalclock

Analogclock And Digitalclock Example (Swipe)

CLASS FILE

package com.example.malik.test;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AnalogClock;
import android.widget.Button;
import android.widget.DigitalClock;
public class MainActivity extends AppCompatActivity {

private static Button button;
private static AnalogClock analogClock;
private static DigitalClock digitalClock;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

button = (Button) findViewById(R.id.bClock);
analogClock = (AnalogClock) findViewById(R.id.analogClock);
digitalClock = (DigitalClock) findViewById(R.id.digitalClock);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(digitalClock.getVisibility() == DigitalClock.GONE){
digitalClock.setVisibility(DigitalClock.VISIBLE);
analogClock.setVisibility(AnalogClock.GONE);
} else {
digitalClock.setVisibility(DigitalClock.GONE);
analogClock.setVisibility(AnalogClock.VISIBLE);
}
}
});

}
}

 

XML FILE

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout 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”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”com.example.malik.test.MainActivity”>
<AnalogClock
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:id=”@+id/analogClock”
android:layout_alignParentTop=”true”
android:layout_centerHorizontal=”true”
android:layout_marginTop=”53dp” />

<DigitalClock
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:id=”@+id/digitalClock”
android:layout_below=”@+id/analogClock”
android:layout_centerHorizontal=”true”
android:layout_marginTop=”53dp” />

<Button
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Swap Clock”
android:id=”@+id/bClock”
android:layout_below=”@+id/digitalClock”
android:layout_centerHorizontal=”true”
android:layout_marginTop=”51dp” />
</RelativeLayout>

 

OutPut :

 

pic

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.