2012-07-01 53 views
0

我有一個ListView在列表的每個項目中包含一個TextView。重複任務:更改ListView中的TextView

<LinearLayout 
......> 
<i>//other views</i> 
..... 
<TextView android:id="@+id/frequently_changing" > <i>//updated every 1s</i> 

</LinearLayout> 

如何改變TextView的出我的例如活動定時器,線程..不具有防僞錯誤「只有創建視圖的UI線程的人必須改變它的權利」

感謝。

回答

0

嘗試使用runOnUiThread從主題更新的TextView作爲

public void myThread(){ 
     Thread th=new Thread(){ 

     @Override 
     public void run(){ 
      try 
      { 

      while(true) 
      { 

      Thread.sleep(100L); //SET INTERVAL TO UPDATE TEXTVIEW TEXT 
      Your_Current_Activity.this.runOnUiThread(new Runnable() { 

      @Override 
      public void run() { 

      TextView txt= (TextView) findViewById(R.id.textview); 
      txt.setText(str); SET TEXT HERE 
      }); 
      } 
      }catch (InterruptedException e) { 
     // TODO: handle exception 
     } 
     } 
     }; 
     th.start(); 
     }