Android:如何将用户输入保存到本地数据?

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

Android:How to save user input to local data?

问题

抱歉,您的描述太长,无法一次性处理。以下是您提供的内容的翻译:

我一直在进行一个小项目研究,没有使用任何安卓工作室,只用Linux终端和我的手机上的AIDE。我成功地创建了一个项目列表,存储在/res/values/strings.xml中,涉及了许多组件和适配器,据我所见。
我的问题是,如何将用户的输入保存到列表中?也许不可能,因为这是一个预编译的列表?
目前,该文本编辑框和添加按钮的脚本都是空的,只是一个示意。
Android:如何将用户输入保存到本地数据?

英文:

I've been doing a small project study without any android studio only terminal on Linux and aide on my phone, I successfully made a list of items that is stored on /res/values/strings.xml, it's involving a lot of components and adapters as I can see.
My question is, how to save user input to the list? Maybe not possible because it's a precompiled list?
That textEdit and addButton has empty script for now, it's just an illustration.
Android:如何将用户输入保存到本地数据?

答案1

得分: 1

作为新手,我建议你在Android中使用“SharedPreferences”。只需将新值存储在数组中,以后想要时检索数组并进行排序。

你也可以使用数据库(Room DB)。但对于存储这个列表来说,这是不必要的。

你可以在网上查找基本的SharedPreferences教程。

英文:

For a newbie, I would suggest you to use "SharedPreferences" in android. Simply store new value in the array and retrieve the array whenever you want and sort it.

You can also use Database (Room DB). But for storing this list.. it is not required.

You can check basic SharedPreferences tutorial online.

答案2

得分: 0

如果您只想处理该 XML 文件,可以按照以下步骤操作:

  1. 当按钮被点击时,通过覆盖 OnClickListener 接口的 onClick() 方法并在其中实现逻辑,从输入中获取值。
  2. 使用 JAXB 将收集到的数据保存到您现有的 XML 文件中。
英文:

If you want to work only with that xml file, you can do the following:

  1. Get the value from input when the button is pressed by overriding the onClick() method from OnClickListener interface and implement there the logic.
  2. Use JAXB to save collected data in your existing XML file.

huangapple
  • 本文由 发表于 2020年10月12日 21:32:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/64318912.html
匿名

发表评论

匿名网友

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

确定