https://kotlinlang.org logo
#android
Title
# android
s

Suraj Sahani

12/12/2023, 6:31 PM
Hi, Everyone. Anyone can help me here. how can i how to add multiple selection in callback, Simply i have Lambda of ListDataResponse, on callback.invoke function i am trying to pass Array of all DataResponse in Lamda, and simply pass that onClick event to Submit view. Code Snippet. Passing this to My Parameter inside Adapter
val callback: ((List<DataResponse>) -> Unit)? = null,
Calling it inside onBindViewHolder
callback?.invoke(selectedOptions).
Current Behaviour. it's taking only simple DataResponse, I am trying to take all values whichever i select here not just single value
not kotlin but kotlin colored 1
f

frank-vu

12/13/2023, 1:37 AM
Can you show the code how you create and add a value to selectedOptions? better to show more code
f

frank-vu

12/13/2023, 4:38 AM
I saw that you are pass : val callback: ((OptionResponse) -> Unit)? = null. . it is not List<DataResponse> . However, I think single instance is good, because in Fragment (where you use Adapter) you can implement this callback and send the new selected option to the ViewModel. ViewModel will keep the list of selected options.
If you want to show the selected options on the list, you should do it in ViewModel by using the list of OptionResponse and list of selected options, then pass the new list to the Adapter.