欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

android應(yīng)用開發(fā):實時改變TextView的值

線程實時刷新TextView值:

成都創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供九江網(wǎng)站建設(shè)、九江做網(wǎng)站、九江網(wǎng)站設(shè)計、九江網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、九江企業(yè)網(wǎng)站模板建站服務(wù),10多年九江做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。

思路:

1)使用handler通知view修改值;

2)標(biāo)志位控制線程的停止/開始;

android應(yīng)用開發(fā):實時改變TextView的值android應(yīng)用開發(fā):實時改變TextView的值

/**

* 1、刷新線程

*

* @author wxm

*

*/

class RefreshThread implements Runnable {

public void run() {

while (isStop) {

try {

handler.sendMessage(handler.obtainMessage());

Thread.sleep(1000);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

}

備注:sendMessage發(fā)送消息

/**

* 2、實時刷新界面

*/

Handler handler = new Handler() {

public void handleMessage(Message msg) {

super.handleMessage(msg);

System.out.println("count--->" + count);

if (count == 5) {

isStop = false;

try {

Thread.sleep(3000);

isStop = true;

count = 0;

new Thread(mRefreshThread).start();

} catch (InterruptedException e) {

e.printStackTrace();

}

}

textview.setText(String.valueOf(count++));

}

};

備注:接收消息,并修改停止/開始標(biāo)志位

3、初始化控件

private TextView textview = null; // TextView 控件

private int count = 0;//初始化數(shù)值

private RefreshThread mRefreshThread = null;//刷新線程

private boolean isStop = true;// 線程控制標(biāo)志

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

textview = (TextView) findViewById(R.id.textview);

mRefreshThread = new RefreshThread();

textview.setText(String.valueOf(count));

new Thread(mRefreshThread).start();// 開始進(jìn)程

}

附件:http://down.51cto.com/data/2364203

網(wǎng)站標(biāo)題:android應(yīng)用開發(fā):實時改變TextView的值
文章地址:http://www.chinadenli.net/article10/peisgo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)品牌網(wǎng)站制作全網(wǎng)營銷推廣移動網(wǎng)站建設(shè)網(wǎng)站維護(hù)做網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司