所以似乎myList.add(s)无效。我只是想知道是否有人能告诉我为什么?对此很新 - 我可以不在我的onActivityResult中调用.add吗?谢谢!
@Override
public void onStart() {
super.onStart();
// get Object from file
Object obj = getObjectFromFile(this, myFileName);
// if obj returns something, check it's type
if (obj != null && obj instanceof ArrayList) {
// use the existing List id it exists
myList = (ArrayList<toDo>) obj; //notice the arraylist is of type student
} else {
// create new List if one doesn't exist
//myList = new ArrayList<String>();
myList = new ArrayList<toDo>();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if ((requestCode == 101) && (resultCode == Activity.RESULT_OK)) {
Bundle myResults = data.getExtras();
String activity1 = myResults.getString("activity");
String description1 = myResults.getString("description");
String date1 = myResults.getString("date");
String assignment1 = myResults.getString("assignment");
txtMsg.setText(description1);
s = new toDo(activity1, description1, date1, assignment1);
myList.add(s);
mArrayAdapter.notifyDataSetChanged();
}
}