變化的TextView文本我想點擊一個按鈕後,做這樣的事情:價值變動
case R.id.bcheckConnection:
if (IPok()) {
PlcState.ErrPlc = false;
Constant.adressIpPlc = adresIp.getText().toString();
final ProgressDialog dialog = ProgressDialog.show(Main.this, "", "Trying to connect...");
new Thread(new Runnable() {
public void run() {
timeout = network.testConnection(Constant.adressIpPlc, 102, 20000);
dialog.dismiss();
}
}).start();
if (timeout > -1) {
PlcState.ErrPlc = false;
stanPolaczenia.setText("Connection established. Timeout = ");
stanTimeout.setText(Long.toString(timeout));
currentIp.setText(Constant.adressIpPlc);
} else {
PlcState.ErrPlc = true;
stanPolaczenia.setText("Error");
stanTimeout.setText("");
currentIp.setText(Constant.adressIpPlc);
}
} else {
Toast.makeText(Main.this, "Wrong IP", Toast.LENGTH_LONG).show();
}
break;
所以是有可能AFTER線程停止運行更改文本?
爲什麼不使用「AsyncTask」?它有'onPostExecute()',它在UI線程上運行。 – Eric
謝謝,我將使用'AsyncTask'。它更有意義。 – iluvatar
那麼是否有可能在onCreate方法中更改value引用的值(findViewById)的TxtView? – iluvatar