如何在列表视图的内容保存到Android中的文本文件? [英] how to save contents of a listview to a text file in android?
本文介绍了如何在列表视图的内容保存到Android中的文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有了一堆内容的ListView和我想知道我怎么可以保存列表视图为文本文件里面的内容?我拉着所有的内容从数据库中。
I have a listview that has a bunch of content and I want to know how I can save the contents inside the list view as a text file? I am pulling all the content from a database.
推荐答案
尝试数组序列(可以序列,并取回对象)
Try array serialization (you can serialize and get back Objects)
ObjectOutputStream out;
Object[] objs = new Object[yourListView.getCount()];
for (int i = 0 ; i < youeListView.getCount();i++) {
Object obj = (Object)yourListView.getItemAtPosition(i);
objs[i] = obj;
}
try {
out = new ObjectOutputStream(
new FileOutputStream(
new File(yourFile.txt)));
out.writeObject(objs);
out.flush();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
这篇关于如何在列表视图的内容保存到Android中的文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文