atom feed4 messages in com.googlegroups.android-developers[android-developers] Re: How do I for...
FromSent OnAttachments
RPOJul 23, 2008 11:34 am 
Romain GuyJul 23, 2008 3:11 pm 
Mark MurphyJul 23, 2008 3:20 pm 
jere...@gmail.comJul 24, 2008 4:53 am 
Subject:[android-developers] Re: How do I force a TextView to draw itself?
From:jere...@gmail.com (jere@gmail.com)
Date:Jul 24, 2008 4:53:33 am
List:com.googlegroups.android-developers

On Jul 23, 2:35 pm, RPO <rpoh@gmail.com> wrote:

I want to display a message in a TextView, then sleep for 2 seconds to allow the user time to read the message, then display a new message. Here is a code snippet:

textArea.setText("This is the first message."); SystemClock.sleep(2000); // sleep for two seconds textArea.setText("This is the second message.");

What happens is that the sleep occurs before the first message is displayed, so the user only sees the second message.

Is there a way to force a redraw before the sleep takes place? Or should I be using a different method to delay for the two seconds?

Thanks!

I would recomend using an animation. take a look at the animation sample code. It will make the widget redraw itself. then create a class that inherits TextView and overwrite onDraw() making sure to class super.OnDraw() so that it still draws the TexView stuff. Since the widget is redrawn constantly, you can use a counter or count time to decide when to show the next message here is some sample code (this is from a chronometer I did that shows milliseconds): The Animator class: public class Animator extends Animation{ @Override public long getDuration() { return super.getDuration(); } @Override public void start() { super.start(); } public Animator() { super(); this.setDuration(Long.MAX_VALUE); } public Animator(Context context, AttributeSet attrs) { super(context, attrs); } } the TextView public class myTextView extends TextView{ public void onDraw(){ super.onDraw(); /// code to draw

} } when you use a custom widget in a xml doc you use the complete java name ( com.myproject.myTextView) as oppose to just the class name when you load the widget into the screen you add the animation by using Animator ani = new Animator(); myTextView view = .... view.setAnimation( ani );

There may be an esier way to make a custom animation, but this way will work. At least you can play around with this idea.