阵列/数据存储选项 [英] Array/Data Storage Options
问题描述
我是新来的Android和试图开发我的第一个应用程序。在我的应用程序,我有一个列表视图的活动,列出了一批专卖店。当应用程序的用户(人谁下载的应用程序),选择自己喜爱的商店,+1应该被添加到存储计数。在一年的特定的时间,我想通过门店数量的数组进行排序并显示新的最喜爱的商店到屏幕上。
I am new to android and trying to develop my first app. In my app, I have a listview activity that lists a group of stores. When the app users (anyone who downloaded the app) select their favorite store, +1 should be added to that store count. At a specific time during the year, I want to sort the array by store count and display the new favorite stores to the screen.
我的问题是,我怎么能存储数据,直到它的时候,我来评估新榜?
My question is, how can I store that data until it's time for me to evaluate the new standings?
推荐答案
我会写值使用ObjectOutputStream到文件:
I would write the values to file using an ObjectOutputStream:
public static void saveArray(String filename, String[] array) {
try {
FileOutputStream fos = openFileOutput(filename, Context.MODE_PRIVATE);
ObjectOutputStream out = new ObjectOutputStream(fos);
out.writeObject(array);
out.flush();
out.close();
} catch (IOException e) {}
}
然后编辑上面字数保存为一个int(或短)阵列。
Then edit the above to save word counts as an int (or short) array.
这篇关于阵列/数据存储选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!