Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

Kotlin
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
Kotlin
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
Posted
Updated 17-Aug-20 19:58pm
v2

1 solution

We can't run that code under the same conditions you do: we don;t have access to the rest of your code or to the data it is working with. And with runtime errors, that's pretty important! Heck, we don;t even know where the error occurs in that code, or what you do to get there.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900