我RecycleView在Fragment. 當我單擊其中的一項時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()
}
}
uj5u.com熱心網友回復:
使用導航組件并順利導航到(action_from1fragment_to2fragment)。
如果你想打開特定的對話框,使用特定的資料片段,你可以在配接器中使用 lambda 來提供 id 給視圖模型,片段。
uj5u.com熱心網友回復:
簡單的答案是將elevation和添加background color到第二個片段的父布局,并設定像clickable和focusable這樣的引數true。您的onClickforrecyclerView作業正常。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/372927.html
標籤:安卓 科特林 android-fragments android-recyclerview
下一篇:我無法從片段活動設定工具列
