PowenKo, Android Tutorial 080-3, Thread, Timer clock whit Timer scheduleAtFixedRateActivity

August 25, 2011   ·   0 Comments



PowenKo, Android Tutorial 080-2, Thread, Timer clock whit Timer scheduleAtFixedRateActivity
Tutorial_thread_TimerScheduleAtFixedRateActivity.java

package com.powenko.Tutorial_thread_TimerScheduleAtFixedRate;

import java.util.Timer;
import java.util.TimerTask;



import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class Tutorial_thread_TimerScheduleAtFixedRateActivity extends Activity {
	private TextView mTextView1;
	int mCount=0;
	   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
        mTextView1=(TextView)findViewById(R.id.textView1);
        
        
        
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
            
            @Override
            public void run() {
                // TODO Auto-generated method stub
                timerMethod();
            }
        }, 0,1000);
    }
    private void timerMethod()
    {
    this.runOnUiThread(generate);
    }
    private Runnable generate= new Runnable() {
 
        @Override
        public void run() {
        	
        	mTextView1.setText("PowenKo Clock:\n Timer: " + mCount);
        	mCount++;
 
        }
    };
}

res\layout\main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
android:id="@+id/textView1"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />

</LinearLayout>

sample code:

Tutorial_thread_TimerScheduleAtFixedRate

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