メモアプリを作ろうとしています。私の問題は、メインページのリストにテキスト ファイル (.txt) を表示することです。リストには、メモのタイトルと内容が表示されます。しかし、カスタム アダプターのコーディング方法がわかりません。
ファイルは次のように保存されます。
final EditText title = (EditText) findViewById(R.id.title);
final EditText note = (EditText) findViewById(R.id.note);
String head = title.getText().toString();
String body = note.getText().toString();
String fullnote = body + "\n" + head;
try {
FileOutputStream fo = openFileOutput(head + ".txt", Context.MODE_APPEND);
fo.write(fullnote.getBytes());
fo.write("\n".getBytes());
fo.write("\n".getBytes());
}
catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
これらのファイルをリストビューにロードしたい:
String[] listItems = {"Item 1", "Item 2", "etc.",};
ListView lv = (ListView) findViewById(R.id.mainpage_list);
lv.setAdapter(new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, listItems));
「アイテム1」「アイテム2」「その他」単なるプレースホルダーです。
ファイル名をアイテムにし、ファイルの内容をサブアイテムにしたいです。私はこれまで ListViews と Adapters を使用したことがないので、ちょっと無知です。前もって感謝します。