Skip to content

Instantly share code, notes, and snippets.

@nontravis
Created January 18, 2017 14:51
Show Gist options
  • Save nontravis/ad0e310fd51b0c6c189ffc5363bc93a9 to your computer and use it in GitHub Desktop.
Save nontravis/ad0e310fd51b0c6c189ffc5363bc93a9 to your computer and use it in GitHub Desktop.
BaseViewGroup_override_method
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