Hi everyone I have a custom object MasterWithValue (an object with a value and a list of Detail objects I have made) which extends a class Master (which has only a name property).
This is the class 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);
}
}
In the onSaveInstanceState() method I have this code:
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable("master_detail_list", (ArrayList<MasterWithValue>)
MasterAndDetailStatistics);
}
Where MasterAndDetailStatistics is a List.
Now in onRestoreInstanceState I have tried this code:
@Override
protected void onRestoreInstanceState(Bundle savedState) {
super.onRestoreInstanceState(savedState);
MasterAndDetailStatistics = (List<MasterWithValue>) savedState.getSerializable("master_detail_list");
}
By I get a type-safety warning: Type safety: Unchecked cast from Serializable to List How can I check it? I read that I should implement the Parcable interface, but I am new to android and I have no idea on how to do that. What should I do?