Search code examples
javaandroidandroid-studioandroid-edittextandroid-animation

Animation yoyo keep run when typing Edittext


when typing edit text yoyo animation keep run how to keep typing show animation Once ?

text_send.addTextChangedListener(new TextWatcher() {
                @Override
                public void afterTextChanged(Editable s) {}
    
                @Override
                public void beforeTextChanged(CharSequence s, int start,
                                              int count, int after) {
    
                 
                }
    
                @Override
                public void onTextChanged(CharSequence s, int start,
                                          int before, int count) {
    
                    if(s.length() != 0) {
    
    
                        YoYo.with(Techniques.SlideInUp)
                                .duration(300)
                                .repeat(0)
                                .
                                        playOn(btn_send);
    
    
    
    
                        btn_send.setImageResource(R.drawable.ic_send);

when typing edit text yoyo animation keep run how to keep typing show animation Once ?


Solution

  • if you want to show it only once when the user starts typing then use a bool to do so

    boolean is_show = false;
    text_send.addTextChangedListener(new TextWatcher() {
                @Override
                public void afterTextChanged(Editable s) {}
    
                @Override
                public void beforeTextChanged(CharSequence s, int start,
                                              int count, int after) {
    
                 
                }
    
                @Override
                public void onTextChanged(CharSequence s, int start,
                                          int before, int count) {
    
                    if(s.length() != 0) {
    
    
                        if(!is_show){
                            is_show = true;
                            YoYo.with(Techniques.SlideInUp)
                                .duration(300)
                                .repeat(0)
                                .
                                        playOn(btn_send);
                          }
    
    
    
    
                        btn_send.setImageResource(R.drawable.ic_send);
    

    or you asking something else?