【发布时间】:2022-01-10 01:14:44
【问题描述】:
我在Fragment 中有RecycleView。当我单击RecyclerView 中的一项时,我想打开新的Fragment。第二个Fragment 没有替换前一个但Fragment 被覆盖
Image。我该如何解决这个问题?
我的适配器:
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
// Get element from your dataset at this position and replace the
// contents of the view with that element
val currentProduct = productList[position]
holder.image.setImageBitmap(currentProduct.image)
holder.title.text = currentProduct.title
holder.price.text = currentProduct.price.toString()+"€"
//Go to product details
holder.itemView.setOnClickListener {
val activity = it.context as AppCompatActivity
val detailsFragment = ProductDetailsFragment()
activity.supportFragmentManager.beginTransaction().replace(R.id.fragment,detailsFragment).addToBackStack(null).commit()
}
}
【问题讨论】:
标签: android kotlin android-fragments android-recyclerview