こんにちは私のアプリケーションでは、ユーザーが入力した文字列情報を保存しています。後で再検索のためにそれらの文字列を直列化します。ファイルを保存する場所にファイルを開くときには、入力された最後の文字列だけが表示されます。私はどこが間違っているのか分かりますか?保存されたオブジェクトをすべて取得できず、リストビューで表示できません
これはretrivalコード
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lightlist);
adapter = new ArrayAdapter<String>(LightList.this, android.R.layout.simple_list_item_1, lightNames);
refreshBut = (Button)findViewById(R.id.button1);
try {
File file = getCacheDir();
fis = new FileInputStream(new File(file, LightSetup.FILENAME));
ois = new ObjectInputStream(fis);
String a;
while((a = (String)ois.readObject()) != null){
adapter.add(a);
setListAdapter(adapter);
}
ois.close();
} catch (FileNotFoundException e) {e.printStackTrace();} catch (StreamCorruptedException e){e.printStackTrace();
} catch (IOException e) {e.printStackTrace();} catch (ClassNotFoundException e) {e.printStackTrace();}
}//end onCreate
であり、これは、シリアル化コードである
ます。public void onClickの(表示arg0に)あなたは間違った方法で2つのことをやっている{
String stringData = data.getText().toString();
try {
File file = getCacheDir();
fos = new FileOutputStream(new File(file,FILENAME));
os = new ObjectOutputStream(fos);
os.writeObject(stringData);
fos.close();
os.close();
} catch (IOException e) {e.printStackTrace();}
Intent i = new Intent("com.Sonny.HCIProject.CreateConfirm");
startActivity(i);
finish();
}//end onClick
あなたのアダプターを投稿する – Blackbelt