Note that there are some explanatory texts on larger screens.

plurals
  1. POThread with (textView and progressbar)
    text
    copied!<p>I am programming an app in Android, where I obtain the data from the microphone, it works fine, I am able to save the amplitude of the sound. And I can update the progresssbar.</p> <pre><code> barraThread = new Thread(new Runnable() { public void run(){ while (isRecording){ actualizarBarra(getAmplitud()); //lector.setText(String.valueOf(getAmplitud())); } } },"barra Thread"); </code></pre> <p>-Where: actualizarBarra(getAmplitud()); update the value of the progressbar with the actual amplitude.</p> <p>My problems is that if I try to update a textView from that point, I get the error (</p> <blockquote> <p>“Only the original thread that created a view hierarchy can touch its views.”</p> </blockquote> <p>So I tried to update the textView using a "Handler" and also using "runOnUiThread(new Runnable() {..." but the app runs very slow and sometime crash. Do you know any way to update the progressbar and the textview at the same time, in a properly way?,</p> <h2>Thanks a lot</h2> <p>Using the the runOnUiThread solution.</p> <pre><code>private void actualizarInterfaz() { runOnUiThread(new Runnable() { @Override public void run() { actualizarBarra(getAmplitud()); lector.setText(String.valueOf(getAmplitud())); } }); } </code></pre> <p>and then in a loop: </p> <pre><code> while(isRecording){ actualizarInterfaz(); } </code></pre> <p>Was no error, just the app get frozen, so I can not see any log at the LogCat, just like is running normally but in fact does not. Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload