Changing text of TextView -- old text doesn't go away (Android 4.1.2)

Posted by Jason Costabile on Stack Overflow See other posts from Stack Overflow or by Jason Costabile
Published on 2013-11-05T00:36:01Z Indexed on 2013/11/08 3:54 UTC
Read the original article Hit count: 440

Filed under:
|

I'm pretty new to Android development. Trying to accomplish something fairly simple -- change some displayed text when a timer ticks. Here's the potentially relevant code:

CountDownTimer currentTimer;
Resources res;
TextView timerText;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_exercise);
    res = getResources();

    timerText = (TextView) findViewById(R.id.timer_text);
}

@Override
protected void onStart() {
    super.onStart();

    //"Get ready" countdown
    currentTimer = new CountDownTimer(5000, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            timerText.setText("" + (int)Math.ceil(millisUntilFinished / 1000.0));
        }

        @Override
        public void onFinish() {
            ...
        }
    };

    currentTimer.start();
}

This works fine on an emulated 4.2.2 device, but on a 4.1.2 device (both physical and emulated), the changed TextView appears as such while the countdown proceeds:

Changed TextView

If you can't tell, that's the numbers 5,4,3 overlayed. So, when I set a new string for the TextView, the new string is displayed but without replacing the old string. Any other TextViews used in my app behave in the same way.

Any ideas what the problem is and how to fix it?

Edit: From the XML layout file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".ExerciseActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:keepScreenOn="true"
    android:orientation="vertical" >

    ...

    <TextView
        android:id="@+id/timer_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textIsSelectable="false"
        android:hint="@string/timer_default" />

    ...

</LinearLayout>

That's all that could be relevant.

© Stack Overflow or respective owner

Related posts about android

Related posts about android-textview