update RecyclerView with Android LiveData

前端 未结 4 1062
感动是毒
感动是毒 2021-01-31 16:13

There are many examples how to push new list to adapter on LiveData change.

I\'m trying to update one row (e.g number of comments for post) in the huge list. It would be

4条回答
  •  萌比男神i
    2021-01-31 16:58

    add context to your adapterClass construstor : AdpaterClass(context: Context)

    then smart cast the context to AppCompactActivity

    livedata.observe(context as AppCompatActivity, Observer {it ->
    
            //perform action on it(livedata.value)
        })
    

    when calling the adapter from anywhere activity, fragment pass the context into the adpater

提交回复
热议问题