the code doestn work well .
when i try to get info from my other fragment it;s show null parameter
is want to send info from adapter recyclerview to a fragment with bundle but just pass null
this is my code reycyclerview
class RecyclerAdapterMain(val product: ArrayList<modelproductmain>) :
RecyclerView.Adapter<recycleradaptermain.viewholder>() {
class ViewHolder(itemview: View) : RecyclerView.ViewHolder(itemview) {
val title: TextView = itemview.product_txt
val price: TextView = itemview.price_product
val imageproduct: ImageView = itemview.product_image
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layoutview = LayoutInflater.from(parent.context).inflate(R.layout.product_items, parent, false)
return ViewHolder(layoutview)
}
override fun getItemCount() = product.size
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val products = product[position]
holder.title.text = products.title
holder.price.text = products.price.toString()
val title = holder.title.text
holder.title.setOnClickListener {
val activity = it.context as AppCompatActivity
activity.supportFragmentManager.beginTransaction()
.replace(R.id.homepage , ItemDetailsfragment())
.commit()
val bundle = Bundle()
bundle.putString("title" , title.toString())
}
}
}
and this is my fragment that i want pass data to it
class ItemDetailsfragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.details_items_page , container , false)
val title = Bundle()
val get = title.getString("title")
d("main" , "$get")
return view
}
}
What I have tried:
i try so much things but it can't worked