2012-12-12 2 views
1

나는이 같은 TableRow 팽창 :안드로이드 타이머 그리고 UI 스레드

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(); 

문제이며, 행, UI가 매우 느리며 타이머가 뒤쳐집니다. onTouchListener()에서 view.setBackGroundColor (Color.BLACK)를 클릭하고 클릭하면 지연됩니다.

+0

하나의 개선점은'findViewById()'를 반복적으로 호출하는 대신'textView2'에 대한 참조를 저장하는 것입니다. 그러나 CountDownTimer는 눈에 띄는 지연을 일으키지 않을 것입니다. 그 밖의 무엇을하고 있습니까? – Sam

+0

내 대답 [여기] (http://stackoverflow.com/questions/3733867/stop-watch-logic) – st0le

+0

에 대한 관심을 가질 수 있습니다 ... –

답변

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 
    } 
    } 
+0

대신에 카운트 다운되도록 포맷 할 수 있습니까? 쪽으로? –

+1

commonsware에서 좋은 답변 http://stackoverflow.com/a/2691510/603233 –

+0

그럼 TableRow onTouchListener가 활성화 된 경우 카운트 다운 타이머가 onTick을하지 않게하려면 어떻게해야합니까? TableRow를 만질 때마다 뒤떨어져 있습니다. –