问题
I have some json collection got from rest api, it defines various parameter types, like:
- spinner with values collection (of string or some class objects with some fields)
- date time field with date value
- text edit field
- set of check boxes (check box defined by id, name - caption, state checked/unchecked)
- set of radio buttons
Each parameter is also named.
What I need: visualise list of items (each item will be one from types described above), let user to adjust values for each of them, retrieve collection (in the same json format) and post modified json to server.
Firs approach I've considered is to dynamically add controls to my layout inside scroll view, corresponding to item type. But I feel this is not good approach, maybe better to user RecyclerView and custom list.
Do you have any ideas how to construct list like that? Afaik Android RecyclerView assumes each list item to have the same layout, is it possible to get what I need?
回答1:
This is something similar to what I had worked on. You'll need to create different viewholders and create types based on type of input required for each item in the collection.
In order to get the latest values user has entered, have them stored in the model class dedicated for the json response, map them and send them back to server.
Check this out : https://guides.codepath.com/android/Heterogenous-Layouts-inside-RecyclerView
I had used TextWatcher to intercept changes made by user to edittext, checkchangelistener for radiobuttons, DateTimePicker with a textview to show date and time.
Use of textwatcher in edittext : How to get the Edit text position from Recycler View adapter using Text Watcher in android
来源:https://stackoverflow.com/questions/55449794/android-recyclerview-with-various-dynamic-content-different-for-each-item