Actually i am getting confused as the scope of the variables inside the method is limited so how come it can check for whether the animation is running or not wont it create a new instance every time a button is clicked as method is called when button is clicked. Can somebody explain it to me as this is working perfectly alright
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment);
myView= (TextView) findViewById(R.id.label1);
myButton= (Button) findViewById(R.id.myButton);
newPlayer = MediaPlayer.create(this, R.raw.soundmusic);
final EnlightenApp instance1 = new EnlightenApp();
myButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
final String answer=instance1.EnlightenMe();
myView.setText(answer);
DoAnimation();
}
});
}
public void DoAnimation(){
ImageView myImage= (ImageView) findViewById(R.id.imageView5);
myImage.setImageResource(R.drawable.ball_animation);
AnimationDrawable ballAnimation=(AnimationDrawable) myImage.getDrawable();
if(ballAnimation.isRunning()){
ballAnimation.stop();
}
ballAnimation.start();
}