【发布时间】:2014-04-27 13:24:52
【问题描述】:
大家好,我有一个自定义对象 MasterWithValue(一个具有值的对象和我创建的 Detail 对象列表),它扩展了一个 Master 类(它只有一个 name 属性)。
这是 MasterWithValue 类:
public class MasterWithValue extends Master {
private String value;
private List<Detail> detailList;
public MasterWithValue(String masterName, String masterValue) {
super(masterName);
this.value = masterValue;
this.detailList = new ArrayList<Detail>();
}
@Override
public int getViewType() {
return super.getViewType();
}
@Override
public View getView(LayoutInflater inflater, View convertView) {
View view;
if (convertView == null) {
view = inflater.inflate(R.layout.statistics_rowlist_master, null);
}
else {
view = convertView;
}
TextView MasterEntryName = (TextView) view.findViewById(R.id.statistics_master_name);
TextView MasterEntryValue = (TextView) view.findViewById(R.id.statistics_master_value);
MasterEntryName.setText(super.name);
MasterEntryValue.setText(this.value);
return view;
}
public String getMasterValue() {
return value;
}
public List<Detail> getDetailList() {
return this.detailList;
}
public void addDetailToMaster(Detail detail) {
this.detailList.add(detail);
}
}
在 onSaveInstanceState() 方法中我有这段代码:
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable("master_detail_list", (ArrayList<MasterWithValue>)
MasterAndDetailStatistics);
}
MasterAndDetailStatistics 是一个列表。
现在在 onRestoreInstanceState 我已经尝试过这段代码:
@Override
protected void onRestoreInstanceState(Bundle savedState) {
super.onRestoreInstanceState(savedState);
MasterAndDetailStatistics = (List<MasterWithValue>) savedState.getSerializable("master_detail_list");
}
我收到一个类型安全警告:类型安全:未经检查的从可序列化到列表的强制转换 如何检查它?我读到我应该实现 Parcable 接口,但我是 android 新手,我不知道如何做到这一点。我该怎么办?
【问题讨论】:
标签: java android serializable