I am thinking that you should implement some kind of logic that helps you restore the state of your Views
. So you should be designing a class, let say ViewDetail
that somehow keeps details about the Views
that you are adding.... type, dimension, etc. This class should implement Parcelable
so you are able to add it to the bundle
.
So you will keep an ArrayList<ViewDetail>
, myViews
where everytime the user adds a new View
you create a new ViewDetail
object that you add to your myViews
array.
And then save your Views
and restore them using those objects:
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
//save your view states
outState.putParcelableArrayList("MY_VIEWS",myViews);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
//get the views back...
myViews=savedInstanceState.getParcelableArrayList("MY_VIEWS");
//TODO: add the views back to your Activity
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…