How To Properly "setMutableVisiblity"?

- 1 answer

I'm trying to create a function, setMutableVisibility. The thing is that I'm supposed to use another function but I got an error. I do not understand why. Furthermore one of my friend just did the same function on his computer but he didn't get the error...

fun setMutableVisibility(view: View, visibility: MutableLiveData<Int>?) {
    val parentActivity: AppCompatActivity? = view.getParentActivity()
    if(parentActivity != null && visibility != null) {
        visibility.observe(parentActivity, Observer{ value -> view.visibility = value?:View.VISIBLE})

AS* is telling me that "parentActivity" is the wrong type, I think it's not the case. But here the advice from AS :

Type mismatch. Required: LifecycleOwner Found: AppCompatActivity?

Thank you for your answers.

*AS: Android Studio



This issue exist due to the fact that older support library does not integrate well with latest lifecycle components and there is some known issue / bug as mentioned by Ian in this post. You need to use latest version of AppCompat to fix this. Try:

implementation 'androidx.appcompat:appcompat:1.1.0-alpha03'

And make sure all other support libraries are also upgraded to compatible version (or same if it exists).