title: How to update a custom view in Android
body: <p>I'm developing a simple custom View to show a gauge composed by a background image above which i print a number (rpm) and draw a pointer.<br>
  To achieve it I defined a class (MyGauge) that extends ImageView class. In the onDraw() member I drawLine() and drawText() a number sent by the activity and collected by SetRpm() member; then I force an invalidate() call.<br>
  The activity runs a Thread (a Runnable instance) to generate a different number every second; the thread dispatches a Message to the activity; the Handler receives the message and sets the number by SetRpm() function.</p>
  
  <p>The error I receive is:  </p>
  
  <pre><code>03-12 09:39:33.280 1796-1827/com.stemmo.termi_up W/dalvikvm: threadid=16: thread exiting with uncaught exception (group=0xb178e678)
  03-12 09:39:33.280 1796-1827/com.stemmo.termi_up E/AndroidRuntime: FATAL EXCEPTION: Thread-78
  android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
  at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:5908)
  at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:869)
  at android.view.ViewGroup.invalidateChild(ViewGroup.java:4253)
  at android.view.View.invalidate(View.java:10539)
  at android.view.View.invalidate(View.java:10494)
  at com.stemmo.termi_up.CustomViews.MyGauge.SetRpm(MyGauge.java:61)
  at com.stemmo.termi_up.GaugeActivity$2.handleMessage(GaugeActivity.java:54)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at com.stemmo.termi_up.GaugeActivity$3.run(GaugeActivity.java:83)
  at java.lang.Thread.run(Thread.java:841)
  </code></pre>
  
  <p>So, the handler is in the thread's context??<br>
  How can i solve it?<br>
  Do I need to AsyncTask object instead of the Runnable one?</p>