Created
January 18, 2017 14:51
-
-
Save nontravis/ad0e310fd51b0c6c189ffc5363bc93a9 to your computer and use it in GitHub Desktop.
BaseViewGroup_override_method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract public class BaseViewGroup extends FrameLayout{ | |
... | |
@Override | |
protected void onRestoreInstanceState(Parcelable state) { | |
if (!(state instanceof ChildSavedState)) { | |
super.onRestoreInstanceState(state); | |
return; | |
} | |
ChildSavedState ss = (ChildSavedState) state; | |
super.onRestoreInstanceState(ss.getSuperState()); | |
onRestoreInstanceChildState(ss); | |
} | |
protected Parcelable onSaveInstanceChildState( ChildSavedState ss ){ | |
ss.childrenStates = new SparseArray(); | |
for( int i = 0; i < getChildCount(); i++ ){ | |
int id = getChildAt( i ).getId(); | |
if( id != 0 ){ | |
SparseArray childrenState = new SparseArray(); | |
getChildAt( i ).saveHierarchyState( childrenState ); | |
ss.childrenStates.put( id, childrenState ); | |
} | |
} | |
return ss; | |
} | |
private void onRestoreInstanceChildState( ChildSavedState ss) { | |
for (int i = 0; i < getChildCount(); i++) { | |
int id = getChildAt(i).getId(); | |
if (id != 0) { | |
if (ss.childrenStates.get(id) != null) { | |
SparseArray childrenState = (SparseArray) ss.childrenStates.get(id); | |
getChildAt(i).restoreHierarchyState(childrenState); | |
} | |
} | |
} | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment