In Java, instantiate an interface object is as easy as new Interface()
... and override all the required functions as below, on AnimationListener
private void doingSomething(Context context) {
Animation animation = AnimationUtils.loadAnimation(context, android.R.anim.fade_in);
animation.setAnimationListener(new Animation.AnimationListener() {
// All the other override functions
});
}
However, in Kotlin when we type
private fun doingSomething(context: Context) {
val animation = AnimationUtils.loadAnimation(context, android.R.anim.fade_in)
animation.setAnimationListener(Animation.AnimationListener(){
// All the other override functions
})
}
It error complaints unresolved References AnimationListener.
As explained in the documentation:
animation.setAnimationListener(object : Animation.AnimationListener {
// All the other override functions
})
Apparently the latest way (using Kotlin 1.0.5) of doing it is now without the parenthesis, given there's no empty constructor for the interface.
animation.setAnimationListener(object : Animation.AnimationListener {
// All the other override functions
})
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