小编bde*_*ott的帖子

使用Runnable和postDelayed更新UI不使用计时器应用程序

我已经看过每一个讨论和我可以找到的关于让它工作的线程,但事实并非如此.我有一个更新文本视图的简单计时器(下例中的mTimeTextField).正在正确执行mUpdateTimeTask运行方法(每秒),但UI /文本字段未更新.

我有基于以下信息的代码:

http://android-developers.blogspot.com/2007/11/stitch-in-time.html http://developer.android.com/resources/articles/timed-ui-updates.html

这是代码:

package com.something.handlertest;

import com.something.handlertest.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Test extends Activity {

    private Handler mHandler = new Handler(); 
    private int labelNo    = 0;
    private long currTime  = 0L;
    private long mStartTime = 0L;
    TextView mTimeTextField;

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

        mTimeTextField = (TextView)findViewById(R.id.timeTextFieldl);

        Button startButton = (Button)findViewById(R.id.start_button);
        startButton.setOnClickListener(new …
Run Code Online (Sandbox Code Playgroud)

multithreading android timer handler postdelayed

22
推荐指数
3
解决办法
5万
查看次数

标签 统计

android ×1

handler ×1

multithreading ×1

postdelayed ×1

timer ×1