【问题标题】:From where to load application content从哪里加载应用程序内容
【发布时间】:2020-04-07 18:40:52
【问题描述】:

我正在构建一个需要将多个长文本加载到多个 Textview 中的应用程序。数据永远不会改变。将数据存储在字符串或一个文本文件中并在每次应用启动时加载它更好吗?

【问题讨论】:

  • 欢迎来到 StackOverflow!请检查我的答案。
  • 如果我已经回答了您的问题,请将我的回答标记为“解决方案”。

标签: java android store


【解决方案1】:

将它们存储在字符串资源 (strings.xml) 中,然后在布局中将它们引用到您的 TextView。像这样:

XML 文件保存在 res/values/strings.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello!</string>
</resources>

此布局 XML 将字符串应用于视图:

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />

您可以通过here了解更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-17
    • 2021-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多