He estado tratando de guardar y cargar un ArrayList de cadenas.No work.Even no veo ningún error también. Por favor.
public class toDoList extends ListActivity {
private Button done;
private ListView theList;
private EditText listItem;
private ArrayList<String> listOfList = new ArrayList<String>();
private ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_to_do_list);
done = (Button) findViewById(R.id.doneBtn);
theList = (ListView) findViewById(android.R.id.list);
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listOfList);
FileInputStream fis;
ObjectInputStream ois;
done.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listItem = (EditText) findViewById(R.id.taskTextView);
if (listItem.getText().toString() == "") {
} else { //adding items to the listview
listOfList.add(listItem.getText().toString());
listItem.setText("");
adapter.notifyDataSetChanged();
}
}
});
setListAdapter(adapter);
try{
fis = openFileInput("ToDo");
ois = new ObjectInputStream(fis);
listOfList = (ArrayList<String>) ois.readObject();
}catch(IOException e){
Log.e("ToDoInput", "Can't import todo");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
@Override
protected void onPause(){
super.onPause();
FileOutputStream fos;
ObjectOutputStream ous = null;
try{
fos = openFileOutput("ToDo", Activity.MODE_PRIVATE);
ous = new ObjectOutputStream(fos);
ous.writeObject(listOfList);
}catch(IOException e){
Log.e("ToDo", "Something wrong with output?");
}finally {
try{
if(ous != null) {
ous.close();
}
}catch(IOException e){
e.printStackTrace();
}
}
}