title: Update View at runtime in Android
body: <p>The example is pretty straightforward: i want to let the user know about what the app is doing by just showing a text (canvas.drawText()). Then, my first message appears, but not the other ones. I mean, i have a "setText" method but it doesn't updates.</p>
  
  <pre><code>onCreate(Bundle bundle) {
      super.onCreate(bundle);
      setContentView(splash); // splash is the view class
      loadResources();
      splash.setText("this");
      boundWebService();
      splash.setText("that"):
      etc();
      splash.setText("so on");
  }
  </code></pre>
  
  <p>The view's text drawing works by doing just a drawText in onDraw();, so setText changes the text but doesn't show it.</p>
  
  <p>Someone recommended me replacing the view with a SurfaceView, but it would be alot of trouble for just a couple of updates, SO... how the heck can i update the view dinamically at runtime?</p>
  
  <p>It should be quite simple, just showing a text for say 2 seconds and then the main thread doing his stuff and then updating the text...</p>
  
  <p>Thanks!</p>
  
  <p>Update:</p>
  
  <p>I tried implementing handler.onPost(), but is the same story all over again. Let me put you the code:</p>
  
  <pre><code>public class ThreadViewTestActivity extends Activity {
  
  Thread t;
  Splash splash;
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      splash = new Splash(this);
      t = new Thread(splash);
      t.start();
  
      splash.setTextow("OA");
      try { Thread.sleep(4000); } catch (InterruptedException e) { }
      splash.setTextow("LALA");
  }       
  }
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>public class Splash implements Runnable {
  
  Activity activity;
  final Handler myHandler = new Handler();
  
  public Splash(Activity activity) {
      this.activity=activity;
  }   
  
  @Override
  public void run() {
      // TODO Auto-generated method stub
  
  }
  
  public synchronized void setTextow(final String textow) {
      // Wrap DownloadTask into another Runnable to track the statistics
      myHandler.post(new Runnable() {
          @Override
          public void run() {
              TextView t = (TextView)activity.findViewById(R.id.testo);
              t.setText(textow);
              t.invalidate(); 
          }                   
      });
  }
  }
  </code></pre>
  
  <p>Although splash is in other thread, i put a sleep on the main thread, i use the handler to manage UI and everything, it doesn't changes a thing, it only shows the last update.</p>