You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
data class NewHomeDataModel(
var viewType: Int = -1,
var displayTitle: String? = null,
var dataList: ArrayList<NewHomeDataItem>? = null,
var chipList: ArrayList<NewHomeChipBucket>? = null,
var isApiCallDone: Boolean = false
)
var homeList = ArrayList()
Basically for a specific index, im updating data List , using below code.
```
val brandDataList = HomeRepository.fetchShopByBrandData(urlParams)
val newHomeDataList = newHomeDataModelLiveData.value
val shopByBrandItem = Gson().fromJson<NewHomeDataModel>(
Gson().toJson(newHomeDataList?.get(position)), NewHomeDataModel::class.java)
val chipList = shopByBrandItem?.chipList?: ArrayList()
for ((index, chip) in chipList.withIndex()) {
chip.selected = if (index == chipIndex) 1 else 0
chipList[index] = chip
}
chipList[chipIndex].isApiCallDone = brandDataList?.size ?: 0 > 0
chipList[chipIndex].dataList = brandDataList
shopByBrandItem.chipList = chipList
newHomeDataList?.set(position, shopByBrandItem)
newHomeDataList?.let {
newHomeDataModelLiveData.postValue(it)
}
class NewHomeDataModel {
var viewType: Int = -1
var displayTitle: String? = null
var dataList: ArrayList<NewHomeDataItem>? = null
var chipList: ArrayList<NewHomeChipBucket>? = null
var isApiCallDone: Boolean = false
}
After converting data class to normal class epoxy exception vanishes and code works fine.
So whats the issue in using data class ?
The text was updated successfully, but these errors were encountered:
you cannot update a mutable list in your class, whether its a data class or not. changing the list updates the list reference that is already bound to your model
you cannot update a mutable list in your class, whether its a data class or not. changing the list updates the list reference that is already bound to your model
but im creating a copy using gson, and why exception arises when using data class and not in using normal class
I have a data class
var homeList = ArrayList()
Basically for a specific index, im updating data List , using below code.
The text was updated successfully, but these errors were encountered: