0

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.

Shaan
  • 17

3 Answers3

2

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

Prajwal Waingankar
  • 2,534
  • 2
  • 13
  • 20
0

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. Animate the transition between fragments

TaQuangTu
  • 2,155
  • 2
  • 16
  • 30
0

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.

Kuruchy
  • 1,330
  • 1
  • 14
  • 26