runOnUiThread()未执行

时间:2015-01-04 13:50:19

标签: android-runonuithread

我想通过此runOnUiThread()操作我的UI。当我删除除语音输出之外的所有内容时,可以执行doStuff。但是当我离开它时,doStuff中没有任何东西被执行。知道为什么没有发生的事吗?

public void doStuff() {
    runOnUiThread(new Runnable() {
        public void run() {
            try {
                Linearlayout layout = (Linearlayout) findViewById(R.id.layout1);
                Button button1 = (Button) findViewById(R.id.button1);
                Button button2 = (Button) findViewById(R.id.button2);

                layout.setVisibility(View.VISIBLE);
                layout.setClickable(true);

                String output = "test test test";
                button1.setText(output);

                String more_output="here it comes";
                button2.setText(more_output);

                String together = output + more_output;
                ttobj.speak(together, TextToSpeech.QUEUE_FLUSH, null); //Speech output
            }catch (Exception e) {

            }
        }
    });
}

1 个答案:

答案 0 :(得分:0)

开始执行以下代码。

      YourAcivityName.this.runOnUiThread(new Runnable)
            @Override public void run() { 
            //your code here
        } 
    });