如何保存的ArrayList中包对象 [英] How to save ArrayList in an Bundle Object
问题描述
喜
我需要找到一种方法来存储帮助
Hi
I need help in finding a way to store
ArrayList<HashMap<String,String>>
在Bunble对象,这样我就可以检索它们放回onRestoreInstanceState(包状态)时的取向发生了。我可以找到方法来存储简单数组在Bunble,而不是像这样一个ArrayList。
in an Bunble object so that i can retrieve them back in onRestoreInstanceState(Bundle state) when an orientation happens .I can find methods to store simple Arrays in an Bunble,but not an ArrayList like this.
推荐答案
首先,你必须有一个静态持有人:
first you must have a static holder:
private static class Holder{
private List<BitmapDrawable>imageList = new ArrayList<BitmapDrawable>();
}
第二,当定向开始,你必须要检索的方向后,退还对象:
second, when orientation start, you must return the object you want to retrieve after the orientation:
@Override
public Object onRetainNonConfigurationInstance() {
return holder;
}
最后,在创建新的活动必须调用getLastNonConfigurationInstance()。 Android将回报你持有人与您的列表中。
at last, when you create the 'new' activity must call getLastNonConfigurationInstance(). ANdroid will return your holder with your List.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
holder = (Holder) getLastNonConfigurationInstance();
}
欢呼声
这篇关于如何保存的ArrayList中包对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!