存储的一个好方法/读取大量的字符串? [英] A good way to store/read a large amount of strings?

查看:283
本文介绍了存储的一个好方法/读取大量的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在开发Android一个搞笑语录应用程序。我有超过1000的报价,我想我的应用程序里使用,但我不知道我是否应该使用一个数据库或文本文件。请注意,应用程序不应该读同一个句子的两倍。它有一个previous /下一个按钮,所以我需要跟踪previous报价。请告诉我哪一个更好,更优化。此外,如果你可以请链接我一个很好的教程有关存储/读取数据。

I'm developing a "funny quotes" app for android. I have over 1000 quotes which I want to use inside my app but I don't know whether I should use a database or text file. Please note that the app should not read the same sentence twice. and it has a previous/next button so i need to keep track of the previous quotes. please tell me which one is better and more optimized. Also, if you can please link me to a good tutorial about storing/reading the data.

感谢

推荐答案

使用的数据库。它比一个文本文件,更快,更灵活。有一天,您将扩展应用程序,那么你会很高兴你使用的数据库。我建议,当你启动应用程序,只需选择使用数据库的内置的随机功能的所有行。 1000行不应太长。然后,只需通过产生的ArrayList(或任何你选择使用),你最终的字符串迭代 - 显示您第一次报价将是元素0从该列表,从该列表的第二个元素元素1,依此类推。如果你使用这种方法,你不需要任何其他的结构,以保持使用引号的轨道 - 只需使用您用于索引引用数组的迭代变量

Use a database. It's faster and more flexible than a text file. One day you will extend the app and then you will be glad you used a database. I recommend to, when you boot up the app, just select all the rows using the in-built random functionality of your database. 1000 rows should not take too long. Then just iterate through the resulting ArrayList (or whatever you choose to use) of strings you end up with - the first quote you show will be element 0 from that list, the second element element 1 from that list, and so on. If you use this approach, you won't need any other structure to keep track of used quotes - just use the iterator variable that you use for indexing the quote array.

fetchAllRows 此页面似乎是你想要的得到的数据。

fetchAllRows on this page seems to be what you want for getting the data.

如果您选择不保存在内存中太多了,你可以继续只是已沿用至今的报价ID列表。该列表的最后一个元素将是目前的报价,和previous元素是当他们preSS后退按钮,用户应该看到什么。

If you choose not to keep too much in memory, you could keep just a list of quote IDs that have been used so far. The last element of that list would be the current quote, and the previous elements would be what the user should see when they press the back button.

这篇关于存储的一个好方法/读取大量的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆