【问题标题】:runOnUiThread() not executedrunOnUiThread() 未执行
【发布时间】:2015-01-04 13:50:19
【问题描述】:

我想通过这个 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) {

            }
        }
    });
}

【问题讨论】:

  • 最坏的主意,空渔获物。用这个看看wrnog是什么,然后检查logcat catch (Exception e) {e.printStacktrace();}
  • 不抛出异常。

标签: android-runonuithread


【解决方案1】:

开始执行如下代码。

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

【讨论】:

    猜你喜欢
    • 2017-02-13
    • 2012-04-17
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    • 1970-01-01
    • 2021-02-07
    • 2021-11-25
    • 1970-01-01
    相关资源
    最近更新 更多