简体   繁体   中英

Transformations.map with ViewModel and LiveData in Androidx (issue)

https://github.com/neuberfran/SmartDrive11/blob/master/app/src/main/java/com/example/neube/smartdrive/controlamotores/SmartViewModel.kt

I have the above project, based on this:

https://firebase.googleblog.com/2017/12/using-android-architecture-components_20.html

and I'm having this image issues:

https://drive.google.com/drive/folders/1_M3KBZnFXkX6I1dMNLejNZAAqrs_QBA9?usp=sharing

Can someone help?

You have imported the wrong function type. it should be androidx.arch.core.util.Function and not import java.util.function.Function

In your Activity: if your ViewModel is kotlin you should reference the livedata like hotStockViewModel.hotStockLiveData since it's a property.

On JVM the properties such as "hotStockLiveData" will have a "get HotStockLiveData" and "setHotStockLiveData" which from kotlin is called like hotStockViewModel.hotStockLiveData, but in JAVA you may use hotStockViewModel.getHotStockLiveData() That's why you can't define a "getHotStockLiveData()" function in the viewModel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM