diff --git a/android-stateful-layout-base/src/main/java/cz/kinst/jakub/view/StatefulLayout.java b/android-stateful-layout-base/src/main/java/cz/kinst/jakub/view/StatefulLayout.java index 9ebbdfa..9d585f1 100644 --- a/android-stateful-layout-base/src/main/java/cz/kinst/jakub/view/StatefulLayout.java +++ b/android-stateful-layout-base/src/main/java/cz/kinst/jakub/view/StatefulLayout.java @@ -27,6 +27,7 @@ public class StatefulLayout extends FrameLayout { private String mState; private OnStateChangeListener mOnStateChangeListener; private boolean mInitialized; + private boolean mDirtyFlag = false; public interface OnStateChangeListener { @@ -86,6 +87,7 @@ public void setStateView(String state, View view) { addView(view); } view.setVisibility(GONE); + mDirtyFlag = true; } @@ -97,10 +99,10 @@ public String getState() { public void setState(String state) { if(getStateView(state) == null) { - throw new IllegalStateException(String.format("Cannot switch to state \"%s\". This state was not defined or the view for this state is null.")); + throw new IllegalStateException(String.format("Cannot switch to state \"%s\". This state was not defined or the view for this state is null.", state)); } - if(mState != null && mState.equals(state)) + if(mState != null && mState.equals(state) && !mDirtyFlag) return; mState = state; @@ -110,6 +112,8 @@ public void setState(String state) { if(mOnStateChangeListener != null) mOnStateChangeListener.onStateChange(state); + + mDirtyFlag = false; }