question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Data-Binding using LiveData

See original GitHub issue

in 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

105reactions
yigitcommented, Jun 3, 2017

We are going to make data binding lifecycle aware but for that to happens, lifecycle needs to hit 1.0 stable api.

32reactions
gaurav414ucommented, Nov 7, 2017

@yigit @JoseAlcerreca Hi! I think, its time to reopen this issue as the lifecycle has already hit 1.0 stable api. Thoughts?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found