Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to animate text change in TextView?

Trying to do the following:

animTimeChange = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left); 
itemTime.startAnimation(animTimeChange);
itemTime.setText("new text");

but the animation happens thru blank screen (i.e. original text is cleared, then new text appears with animation). How to avoid that blank screen?

(my TextView is part of ListView row, I've tried to use TextSwitcher - it doesn't work properly; for ViewFlipper - I am not sure where add Views there, since this is part of the ListView)

like image 281
LA_ Avatar asked Jun 07 '11 20:06

LA_


People also ask

How do you animate TextView?

To start the animation we need to call the startAnimation() function on the UI element as shown in the snippet below: sampleTextView. startAnimation(animation); Here we perform the animation on a textview component by passing the type of Animation as the parameter.

Can we change the text in TextView?

TextView tv1 = (TextView)findViewById(R. id. textView1); tv1. setText("Hello"); setContentView(tv1);

Which method is used to set the text in a TextView?

Set The Text of The TextView You can set the text to be displayed in the TextView either when declaring it in your layout file, or by using its setText() method. The text is set via the android:text attribute.

How do you strikethrough text in TextView?

If you want to show a strike-through text you can do it programming using PaintFlags. You can set paint flags Paint. STRIKE_THRU_TEXT_FLAG to a TextView and it will add a strike-through to the text. TextView textView = (TextView) findViewById(R.


1 Answers

TextSwitcher is exactly what you should be using for this. Check out the API Demo for TextSwitcher.

The way you should implement this is in your ListAdapter, provide TextSwitcher views to the ListView instead of TextViews. Then you can just call TextSwitcher.setText() on the list item you want to change.

Note that you should imediately get rid of your reference to the list item to avoid REALLY messing up listview.

like image 59
CodeFusionMobile Avatar answered Sep 22 '22 22:09

CodeFusionMobile