I have an EditText with android:maxLength="17" and used buttons with onClickListener to update text of this EditText the process here is that when the text length reaches to 16 the EditText animate's towards left with distance of approx one character using TranslateAnimation(0, -15, 0, 0); and then the first character of EditText is being removed. for this first i call the method to perform animation and then call method to remove the the first characer like shown below
animate();
removeChar();
The problem here is that before the end of animation the character got removed, means while the animation is running the removeChar() completes its functionality while i want the removeChar() to perform its functionality after animation ends.
when i googled for this i found answer to use animation listener but while writing code in Eclips i don't found any animation listener for the object
the methods have no error and perform their functionality accurate as i want. the code for methods is show below
public void animate()
{
//slide is declared at class level
slide = new TranslateAnimation(0, -15, 0,0 );
slide.setDuration(1250);
slide.setFillAfter(true);
myEditText.startAnimation(slide);
}
public void removeChar()
{
String update="";
for(int i=1 ; i < myEditText.getText().toString().length() ; i++)
{
update=update+input.getText().toString().charAt(i);
}
myEditText.setText(update);
}
I have also tried to use the code below to wait for end of animation but it halts the application .
animate();
//slide is declared at class level
while(!(slide.hasEnded()))
{
// Just waste the time
}
removeChar();
i think the application halts because all processing goes for while loop and animation doe'nt gots ended and hence loop becomes an infinite loop and causes application to halt
i searched a lot and found no proper answer plz help me and i will prefer a code snippet or a little example as I'm new to android plz really need help...
Open the Settings app, if it's not already open, by swiping down from the top of the screen once (or twice, depending on the brand of device you're using) and tapping the Settings (gear) icon. To speed up, slow down, or disable the animations on your Android device, the Developer options have to be available.
On Android 4.4 (API level 19) and higher, you can use the transition framework to create animations when you swap the layout within the current activity or fragment. All you need to do is specify the starting and ending layout, and what type of animation you want to use.
Attach an AnimationListener
to your animation and then execute removeChar()
in the onAnimationEnd()
method. Like this:
slide.addAnimationListener(new AnimationListener(){
public void onAnimationStart(Animation a){}
public void onAnimationRepeat(Animation a){}
public void onAnimationEnd(Animation a){
NameOfParentClass.this.removeChar();
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With