Data-Binding using LiveData
See original GitHub issuein Basic Sample, ProductFragment.java
// Observe product data
model.getObservableProduct().observe(this, new Observer<ProductEntity>() {
@Override
public void onChanged(@Nullable ProductEntity productEntity) {
model.setProduct(productEntity);
}
});
We observe for a change in LiveData<ProductEntity> mObservableProduct
. When a change is there we set ObservableField<ProductEntity> product
so that the data-binding library updates the UI. It seems like too much work perhaps.
My understanding would be that since LiveData cares about the lifecycle owner and not the view, hence databinding doesn’t support LiveData. Is that so? @yigit If this is the right way of doing it, is there any better way of using Data-Binding with LiveData?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:15 (4 by maintainers)
Top Results From Across the Web
Bind layout views to Architecture Components
You can use LiveData objects as the data binding source to automatically notify the UI about changes in the data. For more information...
Read more >Android MVVM LiveData Data Binding - DigitalOcean
LiveData is a handy data holder that acts as a container over the data to be passed. The best thing about LiveData is...
Read more >Data Binding with LiveData in Android - GeeksforGeeks
We need to declare the data in ViewModel as LiveData, We can use MutableLiveData ( most commonly ) it is just a class...
Read more >How can I do databinding with livedata? - Stack Overflow
It's possible to use data-binding with LiveData<User> but you should transform from User to int or String to use data-binding.
Read more >Advanced Data Binding: Binding to LiveData (One- and Two ...
To use a LiveData object with your binding class, you need to specify a lifecycle owner to define the scope of the LiveData...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We are going to make data binding lifecycle aware but for that to happens, lifecycle needs to hit 1.0 stable api.
@yigit @JoseAlcerreca Hi! I think, its time to reopen this issue as the lifecycle has already hit 1.0 stable api. Thoughts?