0

I have a problem with a textview. When I change the text value with settext, the old value doesn't desapear and the new value is drawn over. So after a few seconds, it's completely illegible. I don't know how to name this bug in english, it's why i post you the folowing screenshot (edit : i can't post it)

My source code :

public class AlarmActivity  extends Activity {

int tempsRestant;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_alarm_pad);

    startCountdown();
}

void startCountdown(){
    //final View view=findViewById(R.layout.activity_alarm_pad).getRootView();
    //final View view=((ViewGroup)findViewById(R.layout.activity_alarm_pad)).getChildAt(0);

    final View view=this.findViewById(android.R.id.content);
    new CountDownTimer(59000, 1000) {
        TextView mTextField = (TextView) findViewById(R.id.countdown);
         public void onTick(long millisUntilFinished) {
             tempsRestant = (int)millisUntilFinished/1000;
            mTextField.post(new Runnable() {
                 public void run() {
                    mTextField.setText("00:" + tempsRestant);
                    ((View)mTextField.getParent()).invalidate();
                 }
             });
             //runOnUiThread(updateTimer());

         }

         public void onFinish() {
             mTextField.setText("Systeme actif");
         }
      }.start();


}
}

I have tried a lot of things with .invalidate() (on the root View, on the parent view), but i always have the same bug...

In fact, i don't understand if it's a problem with the view refresh or with the threads (the countdown thread).

4

1 回答 1

0

您可以尝试此代码,但我认为问题可能出在您的设备上,我在 Android 4.2.2 和 2.2 中尝试了您的代码,它可以工作:

mTextField.setText("");
mTextField.setText("00:" + tempsRestant);
((View) mTextField.getParent()).invalidate();
于 2013-07-18T16:57:40.870 回答