phsycholic
phsycholic

Reputation: 33

runOnUiThread() not executed

I would like to manipulate my UI through this runOnUiThread(). doStuff can be executed when I delete everything in it except the Speech output. But when I leave it like that nothing in doStuff is executed. Any idea why nothing happens?

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) {

            }
        }
    });
}

Upvotes: 0

Views: 103

Answers (1)

keyur thumar
keyur thumar

Reputation: 616

Start execution of code as below.

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

Upvotes: 0

Related Questions