Change animation in runtime
<p>I want to achieve simple tasks - before dialog is dismissed, I want to set different close animation depending on my logic (getWindow().getAttributes().windowAnimations = ...). For examle, I have 2 buttons on dialog and i want to slide left if first is pressed, slide right if second is pressed. I have created style file with some animations for android:windowExitAnimation and android:windowEnterAnimation and they work if passed in custom dialog constructor. But I cant override windowAnimations within the code as constructor approach can no be used as I need different animations. How can it be done and why this code is not working?</p>

<pre><code>        // close button
        _button_close = (ImageButton)findViewById(R.id.buttonClose);

        if (_button_close != null) 
        {
            _button_close.setOnClickListener(
                new Button.OnClickListener() 
                {  
                    public void onClick(View v)
                    {
                        // set animation
                        getWindow().getAttributes().windowAnimations = R.style.DialogSlideOutLeft;

                        // close form
                        dismiss();
                    }
                }
            );
        }   
</code></pre>
