Android animate text when calling setText() -
i want animated text fade in , out when changing extending textswitcher
in order define once since have many textswitcher
objects.
however keep on getting null pointer "java.lang.nullpointerexception android.widget.textswitcher.settext(textswitcher.java:80) when doing :
hometeamtextview.settext("text");
i decided extend textswitcher class this:
public class mytextswitcher extends textswitcher{ public mytextswitcher(context context, attributeset attrs) { super(context, attrs); // todo auto-generated constructor stub setinanimation(context,r.anim.fade_in); setoutanimation(context,r.anim.fade_out); }}
activity
private mytextswitcher hometeamtextview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); hometeamtextview = (mytextswitcher) findviewbyid(r.id.hometeam); awayscoretextview = (textview) findviewbyid(r.id.awayteamscore); homescoretextview = (textview) findviewbyid(r.id.hometeamscore); gamestatustextview = (textview) findviewbyid(r.id.gamestatus); gameclocktextview = (textview) findviewbyid(r.id.gameclock); gamestarttextview = (textview) findviewbyid(r.id.gamestart); gameclocksectiontextview = (textview) findviewbyid(r.id.gameclocksection); loaddataasynctask loaddatatask = new loaddataasynctask(); loaddatatask.execute(); }
layout:
<com.mytextswitcher android:id="@+id/hometeam" android:layout_width="wrap_content" android:layout_height="wrap_content" />
it looks textswitcher common viewswitcher can contain textviews. when call settext() try next view. can find in source: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/widget/textswitcher.java, it's null. think must add textview inside textswitcher (or 2 textview working animation).
Comments
Post a Comment