When using code in the class of the current Activity, everything works:
Animation anim; anim = AnimationUtils.loadAnimation(this, R.anim.alpha_anim); view.startAnimation(anim); When I try to implement the same code in a separate class, the environment emphasizes this in the loadAnimation parameters:
class CustomAnimation implements Animation.AnimationListener { View v; void animation () { Animation anim; anim = AnimationUtils.loadAnimation(this, R.anim.alpha_anim); anim.setAnimationListener(this); v.startAnimation(anim); } @Override public void onAnimationEnd(Animation animation) { v.setVisibility(View.VISIBLE); } @Override public void onAnimationRepeat(Animation animation) { v.setVisibility(View.VISIBLE); } @Override public void onAnimationStart(Animation animation) { v.setVisibility(View.VISIBLE); } } From the Android documentation: Method: loadAnimation (Context context, int id). Parameters: context - Application context used to access resources
Thus, the application context should be passed here. But how to do that? I tried using getApplicationContext (), but the environment curses it, too.
Contextto the constructor 2. get the Context fromView vin the second case, this isAnimationUtils.loadAnimation(v.getContext(), v);- SorryForMyEnglish