1

我像这样给 TableRow 充气:

final TableRow tr1 = (TableRow)LayoutInflater.from(this).inflate(R.layout.attrib_row_survey, null);
tr1.setOnTouchListener(this);
tl1.addView(tr1);

这就是我做计数器的方式:

new CountDownTimer(30000, 1000) {

                 public void onTick(long millisUntilFinished) {
                     ((TextView)tr1.findViewById(R.id.textView2)).setText("Seconds Remaining: " + millisUntilFinished / 1000);
                 }

                 public void onFinish() {
                     ((TextView)tr1.findViewById(R.id.textView2)).setText("DONE");
                 }
              }.start();

问题是,当我运行这个计时器并在行中显示它时,用户界面非常慢并且计时器滞后。当我在 onTouchListener() 中执行 view.setBackGroundColor(Color.BLACK) 并单击它时,它会滞后。

4

1 回答 1

0
protected static void startTimer() {
    isTimerRunning = true; 
    timer.scheduleAtFixedRate(new TimerTask() {
        public void run() {
            elapsedTime += 1; //increase every sec
            mHandler.obtainMessage(1).sendToTarget();

        }
    }, 0, 1000);
}

   public Handler mHandler = new Handler() {

     public void handleMessage(Message msg) {
           StopWatch.time.setText(formatIntoHHMMSS(elapsedTime)); //this is the textview
     }
    }
于 2012-12-12T05:56:08.487 回答