我需要每5秒刷新一次TextViews,我創建了TimerTask(並在contrsuctor中設置了Activity參數),但是出現錯誤,我只能從創建它們的線程訪問小部件。更新TExtViews問題 - 替代擴展TimerTask
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.system_data_show);
currentActivity = this;
Timer timer = new Timer();
timer.schedule(new SystemTimerTask(currentActivity),500, 5000);
///////////////// text views from layout /////////////////////////////////////////////
TextView txtCapture = (TextView) this.findViewById(R.id.txtCapture);
txtCapture.setText("System Data");
TextView txtWorkAllowedValue=(TextView)this.findViewById(R.id.workAllowedValue);
TextView txtBusBroken0Value=(TextView)this.findViewById(R.id.busBroken0Value);
TextView txtBusBroken1Value=(TextView)this.findViewById(R.id.busBroken1Value);
TextView txtShortCircuit0Value=(TextView)this.findViewById(R.id.shortCircuit0Value);
TextView txtShortCircuit1Value=(TextView)this.findViewById(R.id.shortCircuit1Value);
TextView txtErrorConfigurationValue=(TextView)this.findViewById(R.id.errorConfigurationValue);
}
如何刷新此textViews每5秒?有什麼辦法不擴展TimerTask,也許o實現一些接口(我不知道哪個),所以我的SActivity擴展Activity實現了那個接口?