skip to Main Content

in recycler view when click item work and clicked and the fragment open successfully but the date can’t send or error is show in fragment when call the date in Bundle()

//This Code In RecyclerView

    holder.setItemClickListener(object:IItemClickListenerQuran{
        override fun clickedItem(view: View, position: Int) {
            Toast.makeText(activity, "Click At Quran Sora: " + items[position].name,Toast.LENGTH_SHORT).show()

            val bundle = Bundle()
            bundle.putString("SoraName", items[position].name)

            val fragment = SoraDetailsFragment()
            val activity = view.context as AppCompatActivity
            activity.supportFragmentManager.beginTransaction().replace(R.id.main_Fragment_Continer, fragment).addToBackStack(null).commit()

//This Code In Fragment

override fun onCreateView(
    inflater: LayoutInflater, container: ViewGroup?,
    savedInstanceState: Bundle?
): View? {
    // Inflate the layout for this fragment
    val view:View =  inflater.inflate(R.layout.fragment_sora_details, container, false)

    val args = arguments
    val SoraName = args!!.getString("SoraName")
    Log.d("receiver", "SoraName: " + SoraName);

    return view

3

Answers


  1. if you want to pass the data using safeArg, here is the approach
    enter link description here

    Login or Signup to reply.
  2. You are creating bundle . But you didn’t bind the bundle as arguments.
    Try adding this line.

    val bundle = Bundle()
    bundle.putString("SoraName", items[position].name)
    val fragment = SoraDetailsFragment()
    fragment.arguments = bundle // This is where bundle is attached to fragment as arguments
    
    Login or Signup to reply.
  3. You can use this

    val bundle = Bundle()
    bundle.putBoolean("SoraName", items[position].name)
    val fragment = SoraDetailsFragment()
    fragment.setArguments(bundle)
    
    val activity = view.context as AppCompatActivity
    activity.supportFragmentManager.beginTransaction().replace(R.id.main_Fragment_Continer, fragment).addToBackStack(null).commit()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search