3

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.

Faisal
  • 1,332
  • 2
  • 13
  • 29

1 Answers1

1

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

  • True. Was in search of a similar sample to get more insight into it. Thanks anyway, appreciated :) – Faisal Oct 29 '19 at 08:42