需要在RecyclerView中正确的点击位置



当我点击RecyclerView中的图像时,我尝试放大它。到目前为止,一切都很顺利。我现在唯一的问题是它的输出位置的图像总是相同的。换句话说,如果我点击第三张图片,第二张图片会放大,内容正确,但位置错误。这同样适用于点击第一张图片。

这是我的AdapterDetail。kt类:

class AdapterDetail(val context: Context, private val listImg:ArrayList<String>,private var listen: CustomerAdapter.OnItemClickListener): RecyclerView.Adapter<AdapterDetail.MyCustomViewHolder>() {
...
inner class MyCustomViewHolder(view: View):RecyclerView.ViewHolder(view){
val preview_img:ImageView = view.findViewById(R.id.preview_img)
fun bind(item: String){
imgView  = itemView.findViewById(R.id.preview_img)
imgView.setOnClickListener {
listen.onItemClick(imgView, adapterPosition)
}
}
}

override fun onBindViewHolder(holder: MyCustomViewHolder, position: Int) {
val item = listImg[position]
holder.bind(item)

}

在活动中,我需要正确的ImageView位置来膨胀它们:

adapterDetail = AdapterDetail(this, house!!.objektBilder as ArrayList<String>,object:  CustomerAdapter.OnItemClickListener{
override fun onItemClick(view: View, position: Int) {
//Here I need the ImageView that was clicked on in the RecyclerView
var viewPosition = view
zoomImageFromThumb(viewPosition, house!!.objektBilder!![position])
}
})

听起来像是一个问题,因为您使用的是已弃用的adapterPosition。使用bindingAdapterPosition代替,它给出了RecyclerView看到的位置:

listen.onItemClick(imgView, bindingAdapterPosition)

相关内容

  • 没有找到相关文章

最新更新