2013-04-04 67 views
-1

我有問題。 如何只顯示一段時間的字符串,然後textview更改字符串。 希望你能幫助我。如何顯示一段時間的字符串

+0

你想實現什麼?字符串是如何改變的? – Leandros 2013-04-04 13:56:04

+0

發起主題例如'AsyncTask',睡了一陣子然後做了改變。 – David 2013-04-04 13:56:52

+0

這不是一個真正的問題 – Nezam 2013-04-04 14:04:58

回答

3

使用定時器設置文本

_tv = (TextView) findViewById(R.id.textView1); 
    _t = new Timer(); 
    -tv.setText("hi"); 
    _t.scheduleAtFixedRate(new TimerTask() { 
      @Override 
      public void run() { 
       _count++; 

       runOnUiThread(new Runnable() //run on ui thread 
       { 
        public void run() 
        { 

        if(_count==5)//after 5 seconds change the text 
        { 
         _tv.setText("hello"); 
        } 
       } 
       }); 
      } 
     }, 1000, 1000); 

記住要取消計時器完成時。

2

這樣的事情?

  cdt = (new CountDownTimer(5000,1000){ // 5 seconds 
      public void onTick(long millisUntilFinished){ 

      } 

      public void onFinish(){ 
       TextView t = (TextView)findViewById(R.id.myTextView); 
       t.setText("Here is the new text"); 
      } 
     }.start()); 
+0

我會建議使用'Handler.onPostDelayed()'。 – Leandros 2013-04-04 13:56:43

+0

感謝所有的答案,特別是對於你的bflosabre91這是我所需要的。 – Marques 2013-04-04 14:07:13

+0

@Marques如果這是正確的答案,然後接受它,所以它可以幫助其他人 – 2013-04-04 14:12:42