This blog will illustrate about how order custom forms are viewed for events for which they are required in Open Event Android. These forms help the event organizer in gathering more information from the user or attendee. For example, in an event X, the organizer might want to know the state from which the user is from. Let’s head onto the code.
1. Create the CustomForm model
The custom form model is to be created as per the API.
@Type(“custom-form”) |
We can observe that there are some special fields in the model. For example, field “field identifier”, identifies the extra field of an attendee to to be taken in while making an attendee POST request. The field “isRequired” specifies whether the field is required to be taken.
2. Add the function to get custom forms from API
@GET(“events/{id}/custom-forms”) |
3. Modify the code of Attendee Fragment
attendeeFragmentViewModel.getCustomFormsForAttendees(eventId.id) attendeeFragmentViewModel.forms.observe(this, Observer { rootView.register.setOnClickListener { val attendees = ArrayList<Attendee>() |
2. Create two more methods
We create two more methods which help in filling the area, whether it should be a text view or image view. As we are only taking type of text, we are creating EditText for all fields!
private fun fillInformationSection(forms: List<CustomForm>) { for (form in forms) { fun getAttendeeField(identifier: String): String { |
Thus, we have successfully implemented Custom Forms viewing in the app.
Resources
- Kapil (2017) – Add views dynamically in Android: https://www.androidtutorialpoint.com/basics/dynamically-add-and-remove-views-in-android/
- Android – Add views dynamically into a viewgroup: https://www.myandroidsolutions.com/2013/02/10/android-add-views-into-view-dynamically/#.W3stOugzZPY
Tags: GSoC18, FOSSASIA, Open Event, Android, Custom Forms