英文:
What is the best way to store large amounts of text data for lazycolumn elements?
问题
I am writing an application with a dialog system. Dialogues are formed as sequences of cards with specific text. They may alternate or repeat.
The card consists of an id, an image and text. When loading data, depending on the id, the required card will be displayed.
My question is what is the best way to store this data?
I'm guessing 3 options:
- Store data in data classes and text in strings.xml
- Store data in xml format and parse data using xml parser
- Store room database data
Which method is the most practical and preferred in this case?
英文:
I am writing an application with a dialog system. Dialogues are formed as sequences of cards with specific text. They may alternate or repeat.
The card consists of an id, an image and text. When loading data, depending on the id, the required card will be displayed.
My question is what is the best way to store this data?
I'm guessing 3 options:
- Store data in data classes and text in strings.xml
- Store data in xml format and parse data using xml parser
- Store room database data
Which method is the most practical and preferred in this case?
答案1
得分: 1
你提供的三个选项都可以完美地工作!
要在它们之间进行选择,你需要回答一个简单的问题:你是在尝试创建一个动态系统,其中你可以创建和删除卡片,还是它将是静态数据?
重新表述:如果你只打算显示静态数据,那么使用本地数据库来实现一切是否值得付出努力呢?
我个人会使用数据库来实现,因为我至少想要最终有能力做一切动态化。此外:strings.xml
只用于静态 UI 元素,以我个人看来。
希望这有所帮助!祝好!
英文:
All of the three options you provided yourself would work perfectly fine!
To choose in between them you have to answer one simple question: Are you trying to create a dynamic system, in which you can create and delete cards or is it going to be static data?
Rephrased: Is the effort of implementing everything using a local database worth it, if you're just going to display static data?
I personally would implement it using a database, as I'd want to at least have the option to eventually do everything dynamically. Also: strings.xml
is for static UI elements only IMO.
Hope this helped! Cheers
答案2
得分: 1
如果您想使用静态方式。一种选择是将它们存储在枚举类中。由于数据将保持不变
enum class MyCards(val id: String, @DrawableRes val image: Int, @StringRes val text: Int) {
CARD_1("1", R.drawable.card1_image, R.string.card1_text),
CARD_2("2", R.drawable.card2_image, R.string.card2_text),
CARD_3("2", R.drawable.card3_image, R.string.card3_text)
}
枚举可以进行序列化和反序列化,因此以后如果需要,可以在数据库中使用它们。
英文:
If you want to go static. One option could be to store them in an enum class. Since the data will be constant
enum class MyCards(val id: String, @DrawableRes val image: Int, @StringRes val text: Int) {
CARD_1("1", R.drawable.card1_image, R.string.card1_text),
CARD_2("2", R.drawable.card2_image, R.string.card2_text),
CARD_3("2", R.drawable.card3_image, R.string.card3_text)
}
Enums can be serialized and deserialized, therefore you can work with them in a database should that need arise later.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论