title: setBackground in onCreateDrawableState
body: <p>I have a situation where I need to setBackground of my custom button based on a condition dynamically in onCreateDrawableState.
  So my code is like this</p>
  
  <pre><code>public class MyButton extends Button  {
  public boolean nightMode = false;
  private Drawable dayBackground, nightBackgound;
  public MyButton(Context context, AttributeSet attrs) {
      super(context, attrs);
      setDuplicateParentStateEnabled(true);
      TypedArray a = context.getTheme().obtainStyledAttributes(
              attrs,
              R.styleable.QITheme,
              0, 0);
  
      try {
          dayBackground = a.getDrawable(R.styleable.MyTheme_dayBackground);
          nightBackgound = a.getDrawable(R.styleable.MyTheme_nightBackground);
      } finally {
          a.recycle();
      }
  
  }
  @Override
  protected int[] onCreateDrawableState(int extraSpace) {
      int[] state = super.onCreateDrawableState(extraSpace+1);
      if (CurrentThemeManager.isNightMode()) {
          if(nightBackgound != null)
              setBackground(nightBackgound);
      } else {
          if(dayBackground != null)
              setBackground(dayBackground);
      }
      return state;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>But since setBackground calls onCreateDrawableState indirectly, I am getting StackOverflowError due to infinite recursive calls</p>
  
  <pre><code>java.lang.StackOverflowError
          at android.view.ViewGroup.onCreateDrawableState(ViewGroup.java:5370)
          at android.view.View.onCreateDrawableState(View.java:14635)
          at android.view.ViewGroup.onCreateDrawableState(ViewGroup.java:5370)
          at my.mytheme.widget.MyButton.onCreateDrawableState(MyButton.java:69)
          at android.view.View.getDrawableState(View.java:14611)
          at android.view.View.setBackgroundDrawable(View.java:14837)
          at android.view.View.setBackground(View.java:14777)
          at my.mytheme.widget.MyButton.onCreateDrawableState(MyButton.java:76)
          at android.view.View.getDrawableState(View.java:14611)
          at android.view.View.setBackgroundDrawable(View.java:14837)
          at android.view.View.setBackground(View.java:14777)
          at my.mytheme.widget.MyButton.onCreateDrawableState(MyButton.java:76)
          at android.view.View.getDrawableState(View.java:14611)
          at android.view.View.setBackgroundDrawable(View.java:14837)
          at android.view.View.setBackground(View.java:14777)
          at my.mytheme.widget.MyButton.onCreateDrawableState(MyButton.java:76)
          at android.view.View.getDrawableState(View.java:14611)
          at android.view.View.setBackgroundDrawable(View.java:14837)
          at android.view.View.setBackground(View.java:14777)
          at my.mytheme.widget.MyButton.onCreateDrawableState(MyButton.java:76)
          at android.view.View.getDrawableState(View.java:14611)
          at android.view.View.setBackgroundDrawable(View.java:14837)
          at android.view.View.setBackground(View.java:14777)
          at my.mytheme.widget.MyButton.onCreateDrawableState(MyButton.java:76)
          at android.view.View.getDrawableState(View.java:14611)
          at android.view.View.setBackgroundDrawable(View.java:14837)
          at android.view.View.setBackground(View.java:14777)
          at my.mytheme.widget.MyButton.onCreateDrawableState(MyButton.java:76)
          at android.view.View.getDrawableState(View.java:14611)
          at android.view.View.setBackgroundDrawable(View.java:14837)
          at android.view.View.setBackground(View.java:14777)
          at my.mytheme.widget.MyButton.onCreateDrawableState(MyButton.java:76)
          at android.view.View.getDrawableState(View.java:14611)
          at android.view.View.setBackgroundDrawable(View.java:14837)
          at android.view.View.setBackground(View.java:14777)
          at my.mytheme.widget.MyButton.onCreateDrawableState(MyButton.java:76)
          at android.view.View.getDrawableState(View.java:14611)
          at android.view.View.setBackgroundDrawable(View.java:14837)
          at android.view.View.setBackground(View.java:14777)
          at my.mytheme.widget.MyButton.onCreateDrawableState(MyButton.java:76)
          at android.view.View.getDrawableState(View.java:14611)
          at android.view.View.setBackgroundDrawable(View.java:14837)
          at android.view.View.setBackground(View.java:14777)
          at my.mytheme.widget.MyButton.onCreateDrawableState(MyButton.java:76)
          at android.view.View.getDrawableState(View.java:14611)
          at android.view.View.setBackgroundDrawable(View.java:14837)
          at android.view.View.setBackground(View.java:14777)
          at my.mytheme.widget.MyButton.onCreateDrawableState(MyButton.java:76
  </code></pre>
  
  <p>Can someone help me fix this StackOverflowError?</p>