I am a beginner of Android Studio. I actually have two questions. First question is what I wrote in title. I have an ArrayList which saves an object named `EachActivity`. My purpose is to save this ArrayList to a file so it remains after I close it. But I think `fos.write(newActivity)` only works for String type. I don't know how to save my type `EachActivity`.

The second question is, after I have saved it, if I want to use it in ListView, how can I print each activity one by one like the pictures shown? [![enter image description here](https://i.stack.imgur.com/sHyFO.png)](https://i.stack.imgur.com/sHyFO.png)

Thank you! I will really appreciate any help! I will attach my code below.

```
package com.example.counter;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    private static final String FILENAME = "file.sav";
    private ListView oldActivities;
    private ArrayList<EachActivity> activities;
    private ArrayAdapter<EachActivity> adapter;
    private EditText name;
    private EditText currentValue;
    private EditText comment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        name = (EditText) findViewById(R.id.body1);
        currentValue = (EditText) findViewById(R.id.body2);
        comment = (EditText) findViewById(R.id.body3);
        Button saveButton = (Button) findViewById(R.id.save);
        oldActivities = (ListView) findViewById(R.id.activityList);

        saveButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                setResult(RESULT_OK);
                String activityName = name.getText().toString();
                String activityCurrentValue = currentValue.getText().toString();
                int intActivityCurrentValue = Integer.parseInt(activityCurrentValue);
                String activityComment = comment.getText().toString();

                EachActivity newActivity = new EachActivity();
                newActivity.setName(activityName);
                newActivity.setDate();
                newActivity.setInitValue(intActivityCurrentValue);
                newActivity.setCurrentValue(intActivityCurrentValue);
                newActivity.setComment(activityComment);

                activities.add(newActivity);
                adapter.notifyDataSetChanged();
                saveInFile(newActivity);
            }
        });

    }

    private void saveInFile(EachActivity newActivity) {
        try {
            FileOutputStream fos = openFileOutput(FILENAME,
                    Context.MODE_APPEND);
            fos.write(newActivity);
            fos.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

```

My `EachActivity` class is:

```
package com.example.counter;

import java.text.SimpleDateFormat;

/**
 * Created by guanfang on 2017/9/22.
 */

public class EachActivity {
    private String name;
    private String date;
    private int currentValue;
    private int initValue;
    private String comment;

    public void setName(String whatName){
        this.name=whatName;
    }
    public String getName(){
        return this.name;
    }

    public void setDate(){
        SimpleDateFormat sy1=new SimpleDateFormat("yyyy-MM-DD");
        this.date=sy1.format(date);
    }

    public void setCurrentValue(int currentValue){
        this.currentValue=currentValue;
    }

    public int getCurrentValue(){
        return this.currentValue;
    }

    public void setInitValue(int initValue){
        this.initValue=initValue;
    }

    public int getInitValue(){
        return this.initValue;
    }

    public void setComment(String comment){
        this.comment=comment;
    }

    public String getComment(){
        return this.comment;
    }

}

```

My layout main is:

```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/activity"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Activities" />

    <ListView
        android:id="@+id/activityList"
        android:layout_width="fill_parent"
        android:layout_height="263dp"
        android:layout_weight="1"
        android:scrollbars="vertical" >

    </ListView>

    <EditText
        android:id="@+id/body1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbars="horizontal" />
    <EditText
        android:id="@+id/body2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbars="horizontal" />
    <EditText
        android:id="@+id/body3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbars="horizontal" />
    <Button
        android:id="@+id/save"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="save" />

</LinearLayout>

```