android RecyclerView 滑动过程中 Item 组件闪烁问题

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.RecyclerView
import com.tongtong.feat_watch.R
import com.tongtong.feat_watch.net.repository.WatchRepository
import com.tongtong.feat_watch.ui.hall.adapter.HallAdapter
import com.tongtong.feat_watch.ui.hall.adapter.ViewModel
import com.tongtong.feat_watch.ui.hall.bean.HallBean
import com.tongtong.feat_watch.ui.hall.viewmodel.HallViewModel
import com.tongtong.feat_watch.ui.paly.view.scroll.ViewHolder
import com.tongtong.lib_net.onFailedSuspend
import com.tongtong.lib_net.onSucceedSuspend
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import javax.inject.Inject

/**
 * @author: shuhuai
 * @desc:
 * @date: 2025/1/15
 * @version:
 * @remark
 */
class MyAdapter(context: Context?, data: MutableList<HallBean> = mutableListOf()) :
    RecyclerView.Adapter<ViewHolder?>() {
    var context: Context? = context
    var viewModel: ViewModel? = null
    var mies: MutableList<HallBean> = data
        init {
            setHasStableIds(true)
        }

    open fun set(fragment: Fragment): MyAdapter {
        viewModel = ViewModelProvider(fragment).get(ViewModel::class.java)
        return this
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        TODO("Not yet implemented")
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(
            LayoutInflater.from(context).inflate(getLayoutId(), parent, false)
        )
    }

    open fun getLayoutId(): Int = R.layout.layout_hall_item

    override fun getItemCount(): Int {
        return if (mies.isEmpty()) 0 else mies.size
    }

    override fun getItemId(position: Int): Long {
        return mies[position % mies.size].hashCode().toLong()
    }

    //使用接口回调点击事件
    private var mItemClickListener: ItemClickListener? = null

    fun setOnItemClickListener(itemClickListener: ItemClickListener?) {
        this.mItemClickListener = itemClickListener
    }

    interface ItemClickListener {
        fun onItemClick(obj: Any?, position: Int)
    }

    override fun onViewRecycled(holder: ViewHolder) {
        holder.destoryDown()
    }
    
}


@HiltViewModel
class ViewModel @Inject constructor(private val repository: WatchRepository) :
    HallViewModel(repository) {

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值