android-livedata

Difference of setValue() & postValue() in MutableLiveData

寵の児 提交于 2020-02-11 01:41:26
问题 There are two ways that make change value of MutableLiveData . But what is difference between setValue() & postValue() in MutableLiveData . I could not find documentation for same. Here is class MutableLiveData of Android. package android.arch.lifecycle; /** * {@link LiveData} which publicly exposes {@link #setValue(T)} and {@link #postValue(T)} method. * * @param <T> The type of data hold by this instance */ @SuppressWarnings("WeakerAccess") public class MutableLiveData<T> extends LiveData<T

Difference of setValue() & postValue() in MutableLiveData

人走茶凉 提交于 2020-02-11 01:38:48
问题 There are two ways that make change value of MutableLiveData . But what is difference between setValue() & postValue() in MutableLiveData . I could not find documentation for same. Here is class MutableLiveData of Android. package android.arch.lifecycle; /** * {@link LiveData} which publicly exposes {@link #setValue(T)} and {@link #postValue(T)} method. * * @param <T> The type of data hold by this instance */ @SuppressWarnings("WeakerAccess") public class MutableLiveData<T> extends LiveData<T

Android mvvm livedata not observing

二次信任 提交于 2020-02-07 01:31:30
问题 This is my first time using MVVM architecture.I am also using LiveData . I simply retrieve data from server using Retrofit.So upon clicking a button in the View(MainActivity.class) I invoke the ViewModel class's method(handleRetrofitcall()) to take up the duty of Api calling from the Model class(Retrofit Handler.class) .The Model class upon retrieving the data informs the ViewModel of the data(which is actually the size of items).I set the size to LiveData and try to listen for it

Android - Filter LiveData List based on Selected Item change in ViewModel

可紊 提交于 2020-01-29 05:46:16
问题 I have a AndroidViewModel for one of my fragments which contains a LiveData List, and I have another property for selected item of another LiveData List. Below is an example of what I am talking about: class TeamViewModel(app: Application): AndroidViewMode(app) { ... val selectedTeam = MutableLiveData<Team>() val allTeams: LiveData<List<Team>> get() = repository.getAllTeams().toLiveData() val allPlayers: LiveData<List<Player>> get() = repository.getAllPlayers().toLiveData() ... } Note:

Android - Filter LiveData List based on Selected Item change in ViewModel

跟風遠走 提交于 2020-01-29 05:46:04
问题 I have a AndroidViewModel for one of my fragments which contains a LiveData List, and I have another property for selected item of another LiveData List. Below is an example of what I am talking about: class TeamViewModel(app: Application): AndroidViewMode(app) { ... val selectedTeam = MutableLiveData<Team>() val allTeams: LiveData<List<Team>> get() = repository.getAllTeams().toLiveData() val allPlayers: LiveData<List<Player>> get() = repository.getAllPlayers().toLiveData() ... } Note:

How to Return LiveData from Repository

廉价感情. 提交于 2020-01-28 11:34:12
问题 I just can't see how to chain LiveData from Repo to VM, so I have tried to boil this down to the most simple of example!: Fragment class LoginFragment : Fragment() { private lateinit var loginViewModel: LoginViewModel private var mCurrentName = "Blank!" override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { // Inflate the layout for this fragment val binding: LoginFragmentBinding = DataBindingUtil.inflate( inflater, R.layout.login

is observeForever lifecycle aware?

最后都变了- 提交于 2020-01-25 10:21:27
问题 I'm working with MVVM, and I have made different implementations of it, but one thing that is still making me doubt is how do I get data from a Repository (Firebase) from my ViewModel without attaching any lifecycle to the ViewModel. I have implemented observeForever() from the ViewModel, but I don't think that is a good idea because I think I should communicate from my repository to my ViewModel either with a callback or a Transformation. I leave here an example where I fetch a device from

How to update a TextView in Fragment from a second Activity using LiveData?

不打扰是莪最后的温柔 提交于 2020-01-25 06:41:29
问题 I have a fragment that starts a second activity upon some button click. This second activity is where the user makes some selections. I want to update a TextView in the fragment based on the user's selections from the second activity. I am using a ViewModelFactory in order to get access to the same ViewModel in the Fragment from within the second Activity (from the solution from Amir Raza found at: Android LiveData - how to reuse the same ViewModel on different activities?) But the TextView

What's the minimum Android API level for using new Google's Jetpack components

爱⌒轻易说出口 提交于 2020-01-24 15:12:15
问题 I had started to learn RxJava that I knew there's some new Google's components like LiveData, Databinding, etc. I want to know what is the minimum Android's API level to use them. Can I leverage them for example in an older APIs like 21 or 23? 回答1: Right from the Docs https://developer.android.com/topic/libraries/support-library/. Starting with Support Library release 26.0.0 (July 2017), the minimum supported API level across most support libraries has increased to Android 4.0 (API level 14)

Retrofit LiveDataCallAdapter doesn't call function adapt (call)

*爱你&永不变心* 提交于 2020-01-24 13:28:06
问题 Trying to solve this problem about 4 days, help, please. I'm creating an app with rest API (retrofit), try to implement LiveDataCallAdapter from Google samples https://github.com/googlesamples/android-architecture-components/tree/master/GithubBrowserSample, but retrofit doesn't call adapter method adapt for getting a response from the server. I'm edited only NetworkBoundResourse (for working without DB) Trying to put breakpoints, after I start repo (login), LiveDataCallAdapter fun adapt