how to use paging when recyclerview item have another recyclerview

自古美人都是妖i 提交于 2021-01-29 10:54:11

问题


i have a recyclerview item ,it contains an another recyclerview to show image list:

    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">


<android.support.v7.widget.RecyclerView
    android:id="@+id/imageRv"
    android:layout_width="0dp"
    android:layout_height="wrap_content" />

if i use paging in ViewHolder,i have to invoke like this

class GankViewHolder(parent: View) : RecyclerView.ViewHolder(parent) {
private val mContext = parent.context
private val profileIv = itemView.findViewById<AvatarImageView>(R.id.profileIv)
private val titleTv = itemView.findViewById<TextView>(R.id.titleTv)
private val timeTv = itemView.findViewById<TextView>(R.id.timeTv)
private val description = itemView.findViewById<TextView>(R.id.contentTv)
private val imageRv = itemView.findViewById<RecyclerView>(R.id.imageRv)
fun bind(gankModel: GankModel?) {
    gankModel?.let {
        val random = Random()
        val r = random.nextInt(256)
        val g = random.nextInt(256)
        val b = random.nextInt(256)
        profileIv.setTextAndColor(gankModel.who, Color.rgb(r, g, b))
        titleTv.text = gankModel.desc
        timeTv.text = TimeHelper.getLiveTime(gankModel.publishedAt)
        description.text = gankModel.url
    }
    if (gankModel?.images != null && gankModel.images.size != 0) {
        var liveData: LiveData<PagedList<String>> = PagingHelper.getLocalLiveData(gankModel.images)
        imageRv.layoutManager = GridLayoutManager(mContext, 2)
        val adapter = ImagePagingAdapter(object : ImagePagingAdapter.OnItemTouchListener {
            override fun onItemClick(view: View, position: Int) {
            }
        })
        imageRv.adapter = adapter
        liveData.observeForever(android.arch.lifecycle.Observer {
            adapter.submitList(liveData.value)
            LogUtils.e("livedata observer size:" + liveData.hasActiveObservers() + "and:" + liveData.hasObservers())
        })

    }

}

}

but it have no LifecycleOwner in ViewHolder

来源:https://stackoverflow.com/questions/52344563/how-to-use-paging-when-recyclerview-item-have-another-recyclerview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!