Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Data-Binding using LiveData #34

@gaurav414u

Description

@gaurav414u

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions