Android - TextView is not updated. What goes wrong?
<p>I am trying to make a pedometer.
So as can be seen, once the acceleration of one particular direction exceeds 1, the counter increments by 1. Then I wanna display the count number in the textView.
However, the textView is always displayed as "TextView" instead of the desired number.</p>

<p>Any idea? Thanks!</p>

<pre><code>import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity implements SensorEventListener {

    Button startButton;
    Button pauseButton;
    Button resetButton;
    TextView textView;

    private SensorManager sensorManager;
    private long lastUpdate;

    private boolean isCalibrated = false;
    private int referrenceAxis;
    private int stepCounts = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textView = (TextView) findViewById(R.id.textView1);

        // start button
        startButton = (Button) findViewById(R.id.button1);
        startButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

            }
        });

        // pause button
        pauseButton = (Button) findViewById(R.id.button2);
        pauseButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

            }
        });

        // reset button
        resetButton = (Button) findViewById(R.id.button3);
        resetButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

            }
        });

        init();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    public void init() {
        sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        lastUpdate = System.currentTimeMillis();
    }

    public void onSensorChanged(SensorEvent event) {

        if (event.sensor.getType() == Sensor.TYPE_LINEAR_ACCELERATION) {
            long actualTime = System.currentTimeMillis();

            if (isCalibrated &amp;&amp; (actualTime - lastUpdate &gt; 500)) {
                if (event.values[referrenceAxis] &gt; 1) {
                    stepCounts++;
                    textView.setText(String.valueOf(stepCounts));
                }
            }
        lastUpdate = actualTime;    
        }

        if (event.sensor.getType() == Sensor.TYPE_GRAVITY) {
            if (!isCalibrated) {

                if ((event.values[0] &gt;= event.values[1])&amp;&amp;(event.values[0] &gt;= event.values[2]))
                    referrenceAxis = 0;
                if ((event.values[1] &gt;= event.values[0])&amp;&amp;(event.values[1] &gt;= event.values[2]))
                    referrenceAxis = 1;
                if ((event.values[2] &gt;= event.values[0])&amp;&amp;(event.values[2] &gt;= event.values[1]))
                    referrenceAxis = 2;

                isCalibrated = true;
            }
        }
    }

    public void onAccuracyChanged(Sensor sensor, int accuracy) {

    }

    protected void onResume() {
        super.onResume();
        // register this class as a listener for the sensors
        sensorManager
                .registerListener(this, sensorManager
                        .getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION),
                        SensorManager.SENSOR_DELAY_NORMAL);
        sensorManager.registerListener(this,
                sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY),
                SensorManager.SENSOR_DELAY_NORMAL);
    }

    protected void onPause() {
        // unregister listener
        super.onPause();
        sensorManager.unregisterListener(this);
    }

}
</code></pre>

<p>XML is as follows:</p>

<pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" &gt;

    &lt;Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="@string/button1" /&gt;

    &lt;Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button1"
        android:layout_alignBottom="@+id/button1"
        android:layout_centerHorizontal="true"
        android:text="@string/button2" /&gt;

    &lt;Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="@string/button3" /&gt;

    &lt;TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/textview" /&gt;

    &lt;TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="14dp"
        android:text="@string/step_mumber"
        android:textAppearance="?android:attr/textAppearanceLarge" /&gt;

&lt;/RelativeLayout&gt;
</code></pre>
