Created
April 27, 2011 10:18
-
-
Save mohayonao/944018 to your computer and use it in GitHub Desktop.
SimpleClock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mohayonao.SimpleClock; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.os.Handler; | |
import android.widget.TextView; | |
public class Main extends Activity { | |
/** Called when the activity is first created. */ | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
main(); | |
} | |
private void main() { | |
int interval = 100; | |
Handler h = new Handler(); | |
h.post(new Runnable() { | |
private Handler h; | |
private int i; | |
private TextView t; | |
private SimpleDateFormat s; | |
public Runnable init(Handler h, int interval) { | |
this.h = h; | |
this.i = interval; | |
this.t = ((TextView)findViewById(R.id.clock)); | |
this.s = new SimpleDateFormat("HH:mm:ss.SSS"); | |
return this; | |
} | |
public void run() { | |
t.setText(s.format(new Date())); | |
h.postDelayed(this, i); | |
} | |
}.init(h, interval)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="vertical" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
> | |
<TextView | |
android:layout_height="wrap_content" | |
android:id="@+id/clock" android:layout_width="wrap_content" android:layout_centerInParent="true" android:textSize="50dp" android:text="00:00:00.000" android:textStyle="bold"/> | |
</RelativeLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment