PowenKo, Android Tutorial 060-2, Thread, Runnable clock

August 24, 2011   ·   0 Comments

package com.powenko.Tutorial_thread_Runnable;

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

public class Tutorial_thread_RunnableActivity extends Activity {
	// Created by PowenKo.com on 2011/2/23.
	private TextView mTextView1;
	private Handler handler;
	private int mClock=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);
        handler = new Handler();
        handler.postDelayed(runner, 1000);

    }
    final Runnable runner = new Runnable()
    {
        public void run()
        {
        	mClock++;
        	mTextView1.setText("PowenKo.com \n Runnable timer:"+mClock);
            handler.postDelayed(this, 1000);
        }
    };

}
<?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>

<h3>sample code:</h3>

Tutorial_thread_Runnable

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