I'm trying display a timer on my app with a Thread calculating the elapsed time and a Handler to modify the view.

I know that Android doesn't allow other threads that the UI Thread to modify a view, so I use the Handler to do this.

But it seems that it was not effective, because I still have the "**android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.**"

What should I do ?

(Oh, and the code is bellow if this might help)

```
package com.hangin.arround.emergency;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;

public class MainActivity extends SherlockActivity {

    private static final String TAG = "MainActivity";

    private TextView elapsedTime;

    private Button startButton;
    private Button stopButton;

    private boolean shouldContinue = false;
    private Handler mHandler;
    private Runnable runnable;

    private static final int MESSAGE_ELAPSED_TIME = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        // Creating the action bar, initializing my views and stuff

        // Creating the Handler
        mHandler = new Handler() {
            @SuppressLint("SimpleDateFormat")
            @Override
            public void handleMessage(Message msg){
                super.handleMessage(msg);
                switch(msg.what) {
                    case MESSAGE_ELAPSED_TIME :
                        // Converting from milliseconds to a String
                        DateFormat formatter = new SimpleDateFormat("hh:mm:ss.SSS");
                        Calendar calendar = Calendar.getInstance();

                        calendar.setTimeInMillis(msg.arg1);
                        String elapsedTimeString = formatter.format(calendar.getTime());

                        elapsedTime.setText(elapsedTimeString);
                        break;
                    default:
                        break;
                }
            }
        };

        // Creating the Runnable
        runnable = new Runnable(){

            @Override
            public void run() {
                int startTime, actualTime;
                startTime = (int) System.currentTimeMillis();
                Log.d(TAG, "startTime = " + startTime);

                while(shouldContinue) {
                    // Calcul du temps écoulé
                    actualTime = (int)System.currentTimeMillis() - startTime;
                    Log.d(TAG, "actualTime = " + actualTime);

                    // Creating the message sent to the Handler
                    Message elapsedTimeMessage = new Message();
                    elapsedTimeMessage.what = MESSAGE_ELAPSED_TIME;
                    elapsedTimeMessage.arg1 = (int) actualTime;

                    // Sending the message
                    mHandler.handleMessage(elapsedTimeMessage);
                }
            }

        };

        // Adding the OnClickListeners on startButton and stopButton
        startButton.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {

                // Launching Thread 
                (new Thread(runnable)).start();
                shouldContinue = true;
            }
        });

        stopButton.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {

                // Stopping the thread
                shouldContinue = false;
            }
        });
    }   
}

```