Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manipulate properties of Livedata list

Say like LiveData<List<Item> is received from remote and few of the Item's properties are calculated in the device based on some conditions. What would be the best practices to do so. Please suggest.

Say e.g., Item class as below:

class Item{
   int id
   String name
   float location
   float distance 
}

in which the id, name and location of each Item are received from remote but the distance to be calculated from location locally. How to calculate the distance and return a LiveData which can be supplied back to the View?

Appreciate your time and input.

like image 745
Faisal Avatar asked Dec 03 '25 00:12

Faisal


1 Answers

You cant manipulate LiveData, it is an immutable data type. If you want to work with mutable live data you must use the MutableLiveData.

This document told everything about it. https://developer.android.com/topic/libraries/architecture/livedata

like image 180
Ozan türcan Avatar answered Dec 04 '25 15:12

Ozan türcan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!