Powenko > Android > Time > Clock

March 25, 2012   ·   0 Comments

package com.powenko;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.text.format.Time;
import android.widget.TextView;

public class Tutorial_todayClockActivity extends Activity {
	private TextView textView1;

    private Handler handler;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        

        textView1= (TextView)findViewById(R.id.textView1);
        
        handler = new Handler();
        handler.postDelayed(runner, 1000);
    }
    
    final Runnable runner = new Runnable()
    {
        public void run()
        {

            get_today();
            handler.postDelayed(this, 1000);
        }
    };
    
    
    
    private void get_today(){
    	
    	Time today = new Time(Time.getCurrentTimezone());
    	today.setToNow();
    	String t_str_weekday=Fun_get_weekday(today.weekDay);
    	
    			
    	textView1.setText(
    			 t_str_weekday
    			+today.monthDay            // Day of the month (0-31)
    			+today.month             // Month (0-11)
    			+today.year                // Year 
    			+today.format("%k:%M:%S"));  // Current time
    	
    	
    }
    private String Fun_get_weekday(int t_weekday)
    {
    	String t_str_weekday="";
    	switch(t_weekday){

		case 0:
			t_str_weekday="Sunday";  break;
		case 1:
			t_str_weekday="Monday";  break;
		case 2:
			t_str_weekday="Tuesday";  break;
		case 3:
			t_str_weekday="Wednesday";  break;
		case 4:
			t_str_weekday="Thursday";  break;
		case 5:
			t_str_weekday="Friday";  break;
		case 6:
			t_str_weekday="Saturday";  break;
    	}
    	return t_str_weekday;
    }
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

</LinearLayout>
shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Android7

Amazon

adsbygoogle

Recent Posts

Categories

Amazon