当我调用listenButton.setAlpha((float)1)
下面的代码时,我收到错误“android.view.ViewRootImpl$CalledFromWrongThreadException:只有创建视图层次结构的原始线程才能触摸其视图”。我明白为什么,但是当我收到 onDone 事件时如何修改按钮?
public class MainActivity extends ActionBarActivity implements TextToSpeech.OnInitListener {
[...]
@Override
// OnInitListener method to receive the TTS engine status
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
ttsOK = true;
tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
public void onDone(String utteranceId) {
Button listenButton = (Button) findViewById(R.id.listentts);
listenButton.setAlpha((float)1);
listenButton.setClickable(true);
}
@Override
public void onError(String utteranceId) {
Log.d("MainActivity", "Progress on Error " + utteranceId);
}
@Override
public void onStart(String utteranceId) {
Log.d("MainActivity", "Progress on Start " + utteranceId);
}
});
}
else {
ttsOK = false;
}
}
[...]
}