最佳方式存储大量文本数据以供lazyColumn元素使用是什么?

huangapple go评论63阅读模式
英文:

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:

  1. Store data in data classes and text in strings.xml
  2. Store data in xml format and parse data using xml parser
  3. 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:

  1. Store data in data classes and text in strings.xml
  2. Store data in xml format and parse data using xml parser
  3. Store room database data

Which method is the most practical and preferred in this case?
最佳方式存储大量文本数据以供lazyColumn元素使用是什么?

答案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.

huangapple
  • 本文由 发表于 2023年4月13日 15:04:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76002547.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定