在Android中设计大数据输入表单

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

Designing Huge Data input form in Android

问题

我相对于Android编程还比较新。我有一个需求,我想从用户那里获取大约30个不同的输入(例如姓名、出生日期、个人数据等)。我绝对不想只使用一个屏幕来获取用户输入,而是可能要使用一个带有"下一步"/"上一步"按钮的选项卡式输入表单。最后,我想要一个"保存"按钮,这样我就可以将这些数据添加到数据库中。另外,在编辑时想要使用同一个屏幕,只是数据将会被预填充。有人能建议一下如何以最佳方式实现这一点,并提供一些示例代码吗?

英文:

I am relatively new to Android programming. I have a requirement where I want to get around 30 different inputs from user (e.g. Name, DOB, personal data, etc). Definitely I don't want to have single screen to get user input, but possibly a tab kind of input form with Next/Previous button. At the end want to have Save button so that I can add this data to database. Also, on the edit want to use same screen, just that data will be pre populated. Can someone advise what is the best possible way to achieve this with some sample code.

答案1

得分: 2

根据用户体验,表单应该在单个屏幕上,大多数用户更喜欢这种方式。在您的情况下,使用 ScrollView,因为表单太大。

更多信息,请参考官方文档:
Android 官方文档

英文:

As per UX the form should be in a single screen mostly users prefer that way. Make use of ScrollView in your case as the form is too big.

Follow the official documentation for more info:
android official

答案2

得分: 0

我建议一个解决方案,就是使用片段(fragment)。您只需要一个活动(activity),每个页面都将是包含用户输入的片段。

如何将片段添加到活动中?

https://developer.android.com/guide/components/fragments#Adding

在片段中保存数据? - 将数据保存到从fragment.getArguments()获取的Bundle中。

在活动中有了片段,并且希望在它们之间进行切换时,您可以使用动画来提供更好的用户体验。

https://stackoverflow.com/questions/4932462/animate-the-transition-between-fragments

英文:

I suggest a solution, it is using fragment. You need only one activty, each page will be a fragment containing user inputs.

How to add fragment(s) to an activity?

https://developer.android.com/guide/components/fragments#Adding

Saving data in fragment? - save to Bundle token from fragment.getArguments().

After having fragments in an activity and want to transit between them. You can use animation to make better UX. https://stackoverflow.com/questions/4932462/animate-the-transition-between-fragments

答案3

得分: 0

我建议整个流程只使用一个Activity,然后为要向客户询问的每个相关数据创建一个Fragment。类似以下方式:

  • Fragment 1:名字,姓氏
  • Fragment 2:出生日期
  • Fragment 3:地址
  • ...
  • Fragment n:完成屏幕

然后,我会利用viewmodelsrepository将视图与数据库连接起来。

每个Fragment中的数据更改将仅更改viewmodel中的livedata,并且只有在用户完成流程并在最后一个屏幕上单击完成按钮后才会保存。

对于编辑,您只需要通过repository访问已存储在数据库中的数据以填充流程,因为一旦从那里检索数据,由于您将使用live data,因此Fragment将观察此live data,因此您的Fragment将被更新。

要处理Fragment之间的过渡,我建议使用navigation component

英文:

I suggest having only one Activity for the hole flow, then I would create a fragment for each related data you want to ask to the customer. Something like the following:

  • Fragment 1: Name, Surname
  • Fragment 2: DOB
  • Fragment 3: Address
  • ...
  • Fragment n: Finishing Screen

Then I would make use of viewmodels and repository to connect the views with the DB.

The data change in each fragment would only change the livedata in the viewmodel, and would only be saved once the user completes the flow and clicks on the finishing button on the last screen.

For editing, you would only need to access the data already stored in the DB via the repository to populate the flow, because once you retrieve the data from there, since you would be using live data and therefore the fragments would be observing this live data, your fragments would be updated.

For handling transitions between fragment I would recommend to use the navigation component.

huangapple
  • 本文由 发表于 2020年1月6日 02:18:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/59602867.html
匿名

发表评论

匿名网友

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

确定