Created
August 5, 2012 04:49
-
-
Save gabu/3261742 to your computer and use it in GitHub Desktop.
ちゃんとArrayListの中身までデシリアライズできるから不思議!
This file contains hidden or 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
public class CopyOfRecipe056Activity extends ListActivity { | |
ItemAdapter mAdapter; | |
ArrayList<Item> mItems; | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
if (savedInstanceState == null) { | |
mItems = new ArrayList<Item>(); | |
} else { | |
// ちゃんとArrayListの中身までデシリアライズできるから不思議! | |
mItems = (ArrayList<Item>) savedInstanceState.getSerializable("items"); | |
} | |
mAdapter = new ItemAdapter(this, mItems); | |
setListAdapter(mAdapter); | |
} | |
class Item { | |
int resId; // アイコン画像リソースID | |
String name; // ユーザ名 | |
String comment; // コメント | |
Item(int resId, String name, String comment) { | |
this.resId = resId; | |
this.name = name; | |
this.comment = comment; | |
} | |
} | |
@Override | |
protected void onSaveInstanceState(Bundle outState) { | |
super.onSaveInstanceState(outState); | |
// リストデータを保存 | |
outState.putSerializable("items", mItems); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Itemクラスをimplements Serializableしなくてもフィールドの値までちゃんと復元できる点が不思議です。
ArrayListが頑張ってるのかなぁ?