samedi 26 septembre 2015

Identify when default Android Checkbox animation ends

When clicking on a Checkbox, a default Android material design animation is triggered (from blank to a "V" mark, and from "V" mark to a blank).

I want to identify when the animation ends.

According to documentation, this should be possible in one of two ways -

  • When the checkbox is checked or unchecked (setOnCheckedChangeListener()), obtain the current Animation object (getAnimation()) and register a listener on it (setAnimationListener()). Unfortunately, this doesn't work - the Animation object, at this point in time, is null.

  • Subclass the Checkbox object and implement its onAnimationEnd() method. Unfortunately, this doesn't work as well - the method is never called.

What am I missing? What is a good way to identify when such a default animation ends? I assume the relevant events can be registered on some other view in the activity, but I can't figure out which.

Here is a relevant code snippet for the first approach (animation is always null) -

    CheckBox checkBox = (CheckBox)findViewById(R.id.checkbox1);
    checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            Animation animation = compoundButton.getAnimation();
            Log.d("Checkbox", "Animation is " + animation);
       }
   });




Aucun commentaire:

Enregistrer un commentaire