0
I can’t get this Animation to run in my Textviews, and the same (animation) runs without any Textview or anything like that in my Activity:
See, even if I add Components to my Activity, they disappear in execution:
Typewriter.class:
package genesysgeneration.animatedtext;
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.widget.TextView;
public class TypeWriter extends TextView {
private CharSequence mText;
private int mIndex;
private long mDelay = 500;
public TypeWriter(Context context){
super(context);
}
public TypeWriter(Context context, AttributeSet attrs){
super(context, attrs);
}
private Handler mHandler = new Handler();
private Runnable characterAdder = new Runnable() {
@Override
public void run() {
setText(mText.subSequence(0, mIndex++));
if (mIndex<=mText.length()){
mHandler.postDelayed(characterAdder, mDelay);
}
}
};
public void animateText(CharSequence text){
mText=text;
mIndex=0;
setText("");
mHandler.removeCallbacks(characterAdder);
mHandler.postDelayed(characterAdder, mDelay);
}
public void setCharacterDelay(long millis){
mDelay=millis;
}
}
An error appears on the following line => public class TypeWriter extends TextView {
, but nothing to prevent the implementation of the.
Mainactivity:
package genesysgeneration.animatedtext;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TypeWriter writer = new TypeWriter(this);
setContentView(writer);
writer.setCharacterDelay(150);
writer.animateText("(nova execução) Pirulito ki bate bate, pirulito ki jah bateu!!!");
}
}
I would like to know how to make sure that other Components are not deleted and that animation is executed in all Textviews that are added to Activity.
fixed setContext, but an error occurred while inserting textView. it did not accept my textView as Typewriter
TypeWriter writer = (TypeWriter)findViewById(R.id.tv);
accused a mistake.– Boneco Sinforoso
So in xml this view whose id is "tv" is not type Typewriter...
– Mr_Anderson
just type <Typewriter ... that Android studio will auto-complete for you with the correct import packages.
– Mr_Anderson