android - wait for animation to complete before hiding View -


i perform things triggered button click:

    private void onsearchpressed() {      title.setvisibility(view.gone);     etactionsearch.setvisibility(view.visible);     etactionsearch.requestfocus();     btnactionfavs.setvisibility(view.gone);     etactionsearch.setanimation(animationutils.loadanimation(             getapplicationcontext(), r.anim.et_anim_open));     issearch = true;  } 

so hide views , show others, edittext "sliding out" using simple set animation.

when action cancelled, reverse process:

    private void onsearchcancelled() {             etactionsearch.setanimation(animationutils.loadanimation(             getapplicationcontext(), r.anim.et_anim_close));     etactionsearch.setvisibility(view.gone);     btnactionfavs.setvisibility(view.visible);     title.setvisibility(view.visible);     issearch = false;  } 

what i'd apply animation (opposite direction) edittext, disappears slide animation. problem code executed immediately, edittext gone before animation complete. tried weird things using asynctask , putting animation inside doinbackground() method, setting visibility of views in onpostexecute() didnt change anything.. systemclock.sleep() doesn't lag impression. solutions?

like marcin orlowski said, have use animationlistener animation. after animation ended launch onanimationend() event can stuff.

here's little example like:

animation animation = animationutils.loadanimation(getapplicationcontext(), r.anim.your_specific_animation); animation.setanimationlistener(new animationlistener() {          @override         public void onanimationstart(animation animation) {         }          @override         public void onanimationrepeat(animation animation) {         }          @override         public void onanimationend(animation animation) {             // hiding stuff here         }     });  etactionsearch.startanimation(animation); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -