2008年10月2日 星期四

即時更新TextView.setText()顯示的方法

你需要額外的Handler來作更新動作,而非直接在想更新的地方更新

所以要在Activity中:

public void onCreate(Bundle savedInstanceState) {
...
 mHandler = new Handler() {
  @Override
  public void handleMessage(Message msg) {
   if (msg.what == 0) {
    mTextView.setText(mText);
   }
  }
 };
}

@Override
public void updateTextView(CharSequence text) {
 mText = text;
 mHandler.sendEmptyMessage(0);
}

然後呼叫這個updateTextView()就可以達到即時更新了(mText和mHandler都要是Activity的field)

沒有留言:

CODE { display: block; /* fixes a strange ie margin bug */ font-family: Courier New; font-size: 8pt; overflow:auto; background: #f0f0f0 url(http://klcintw.images.googlepages.com/Code_BG.gif) left top repeat-y; border: 1px solid #ccc; padding: 10px 10px 10px 21px; max-height:200px; height:200px; // for IE6 line-height: 1.2em; } #quote { display: block; /* fixes a strange ie margin bug */ font-family: Verdana; font-size: 10pt; overflow:auto; background: #f7f7f7 url(http://lh5.ggpht.com/_z-VThISftkI/SXUlpyfw9ZI/AAAAAAAABYY/e3GUx9_Z4TE/s288/quote-l.gif) left top no-repeat; border: 4px dotted #ccc; padding: 15px 15px 15px 31px; /*up right bottom left*/ max-height:300px; line-height: 1.2em; }